Skip to content

Commit

Permalink
Update the Troubleshooting Section (#91)
Browse files Browse the repository at this point in the history
* Update troubleshooting section with regards to ES6 builds

* Change word
  • Loading branch information
makoru-hikage authored Aug 12, 2021
1 parent b8314f2 commit a2d1805
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,28 @@ For the moment, please refer to [Jest.mli](https://github.com/glennsl/bs-jest/bl

## Troubleshooting

If you encounter the error `SyntaxError: Cannot use import statement outside a module`, it may be that you are mixing `es6` and `commonjs` modules in your project. Please take a look at [#63](https://github.com/glennsl/bs-jest/issues/63) for ideas on how to fix this.
If you encounter the error `SyntaxError: Cannot use import statement outside a module`, it may be that you are mixing `es6` and `commonjs` modules in your project. For example, this can happen when you are building a React project since React builds are always in ES6. To fix this, please do the following:

- Make sure your `bsconfig.json` compiles `"es6"` or `"es6-global"`:
```json
"package-specs": {
"module": "es6",
}
```
- Install [esbuild-jest](https://github.com/aelbore/esbuild-jest) through `yarn` or `npm` as a `devDependency`.
- Build your Rescript project with deps: `rescript build -with-deps`.
- Add this to your Jest config (or `jest` of your `package.json`):
```json
{
"transform": {
"^.+\\.jsx?$": "esbuild-jest"
},
"transformIgnorePatterns": ["<rootDir>/node_modules/(?!(rescript|@glennsl/bs-jest)/)"]
}
```
- The property `"transformIgnorePatterns"` is an array of strings. Either you do some regex or organize them in an array. **Please make sure all folders in `node_modules` involving compiled .res/.ml/.re files and the like such as `rescript` or `@glennsl/bs-jest` are mentioned in the aforementioned array.**

This problem is also addressed in [Issue #63](https://github.com/glennsl/bs-jest/issues/63).

## Contribute

Expand Down

0 comments on commit a2d1805

Please sign in to comment.