Can't figure out how to resolve these errors yet, Jest is plaining about dynamic imports like these:
const importModules = Promise.all([
import('containers/HomePage/reducer'),
import('containers/HomePage/sagas'),
import('containers/HomePage'),
]);
Error message:
F:\react-boilerplate\app\store.js:49
import('./reducers').then(function (reducerModule) {
^^^^^^
SyntaxError: Unexpected token import
You can find all of the details here:
Can't figure out how to resolve these errors yet, Jest is plaining about dynamic imports like these:
const importModules = Promise.all([
import('containers/HomePage/reducer'),
import('containers/HomePage/sagas'),
import('containers/HomePage'),
]);
Error message:
F:\react-boilerplate\app\store.js:49
import('./reducers').then(function (reducerModule) {
^^^^^^
SyntaxError: Unexpected token import
You can find all of the details here: https://github./mxstbr/react-boilerplate/pull/1358
Share Improve this question edited Dec 17, 2016 at 9:45 Dattaya asked Dec 16, 2016 at 21:57 DattayaDattaya 93911 silver badges15 bronze badges 4-
what does your
.babelrc
looks like? – Andreas Köberle Commented Dec 17, 2016 at 14:36 - It looks like this: github./Dattaya/react-boilerplate/blob/… – Dattaya Commented Dec 17, 2016 at 14:40
-
1
Have you tried to use the same plugins for prod and test. Seems like babel cant pile the stuff with your babel
env.test
settings – Andreas Köberle Commented Dec 17, 2016 at 18:26 -
Thank you @AndreasKöberle for your suggestion, I added
babel-plugin-dynamic-import-node
plugin to the list of plugins in test environment and the error was resolved for the most parts. I guess dynamicimport()
s can't be polyfilled so the only choice for node is to transform them torequire
inside aPromise
. – Dattaya Commented Dec 17, 2016 at 20:52
2 Answers
Reset to default 7Installing babel-plugin-dynamic-import-node
solved our problem. In addition, make sure that babylon
(babel
dependency) is at least 6.12.0
.
Also, we had a problem with Travis build because Travis cached node_modules
and old babylon
with it:
$ npm ls babylon
[email protected] /home/travis/build/mxstbr/react-boilerplate
├─┬ [email protected]
│ └── [email protected]
├─┬ [email protected]
│ └── [email protected]
├─┬ [email protected]
│ └─┬ [email protected]
│ └── [email protected]
, so we had to turn the cache off with: cache: false
It looks like jest cant pile your files with the babel settings for test
in your .babelrc
file. You need to have the same settings for prod
and test