I'm using Mocha to test a react/webpack/babel application that is written in es6 stage-0 syntax, which includes dynamic imports. Webpack compiles it without errors, but mocha throws the following error when reaching a dynamic import syntax:
import('path/to/file').then(...)
^^^^^^
SyntaxError: Unexpected token import
The command that i'm running is:
$ mocha --compilers js:babel-register src/**/*.test.js
And in my .babelrc
I have to following:
{
"presets": ["es2015", "react", "stage-0"]
}
As @louis has mentioned, this is a node issue. The solution is to add the dynamic-import-node plugin to babel:
{
"presets": ["es2015", "react", "stage-0"],
"plugins": ["dynamic-import-node"]
}
Which will add support for the import(...)
syntax in node.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With