Problem with bsconfig.json when running tests


I created a new project using reason-scripts. When I run yarn test, I get this error:

 FAIL  src/
  ● Test suite failed to run

    import * as List from "bs-platform/lib/es6/list.js";

    SyntaxError: Unexpected token *

      at new Script (vm.js:74:7)
      at Object.<anonymous> (src/

In my bsconfig.json, if I change package-specs from es6 to commonjs, the tests pass. However, I generally want to compile as es6 so that I get dead code elimination. What’s the workaround for this? Write a script that automatically changes package-specs to commonjs whenever I want to run my tests?


This is a huge problem for Reason-scripts. There isn’t a workaround atm, and it’s just a bad situation.


There’s a couple of things you can do @feihong. I’m assuming you are using Jest? Perhaps even Create React App? The simplest thing is to compile to commonjs modules rather than es6 (lame I know) this will fix the issue because Jest by default doesn’t handle es6, at least with my limited experience at configuring it.

The Reason version of react-scripts has it configured properly so you can use es6 module, I just converted my project over to that. It has the added benefit of allowing you to import .re files in JS. The downside for me was the fact that default local imports would favor a file of the same name as the reason one which caused a lot of issues for me.

Hopefully there will be a better solution in the future.


Does the latest reason-scripts work with ES6 modules + tests?


I actually have this figured out sometimes ago. I’ll dig my old code tomorrow for the configuration.


It should :slight_smile:


Has anyone managed to find a solution to this yet?


@justgage I’m looking at bsconfig.json in master, and it looks like they “fixed” it by setting package-specs/module to commonjs.


I know Jest can be configured to work with es6, it’s just tricky


My advice: don’t use reason-scripts.