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.


Last reply on this was back in August. Has the situation improved at all? I “solved” my testing problem by writing a script that converts package-specs/module to commonjs while running tests and then automatically changes it back after tests have finished running. But this is hacky and also takes a long time because it recompiles everything when you change package-specs/module.

@thangngoc89 can you show us how you solved it?


I had a similar issue in a project set up with create-react-app.

My solution was to add the following jest configuration:

yarn run test --transformIgnorePatterns "node_modules/(?!(bs-platform|reason-react|@glennsl\/bs-jest)/)"

Here I’ve listed 3 libraries (bs-platform, reason-react and @glennsl/bs-jest) but you should add any other reason libraries that you’re using.

The default create-react-app jest configuration does not transform node_modules with babel. This flag tells jest to skip transforming apart from the listed libraries. The libraries’ code will be transformed, thus allowing jest to understand the import statement.

Jest testing with ReasonML & Create-React-App

You can configure bsconfig to output both at the same time.

I am a bit confused, this is not a jest issue, did we output invaild es6 code?


I figured out the problem: Jest assumes all the dependencies in node_modules are built in commonjs, which is not the case for BuckleScript. This seems to be the case to for many react-native deps. More info:

Following the default Babel setup in the Jest docs, and adding the following to package.json fixes it:

  "jest": {
    "transformIgnorePatterns": [

Depending on the project, other BuckleScript dependencies used in the tests might need to be added that regexp.

I set up a demo repo in