Jest中的动态导入产生:SyntaxError:意外的令牌导入

Dat*_*aya 5 javascript reactjs jestjs babeljs

目前尚无法解决这些错误,Jest抱怨这样的动态导入:

const importModules = Promise.all([
      import('containers/HomePage/reducer'),
      import('containers/HomePage/sagas'),
      import('containers/HomePage'),
    ]);
Run Code Online (Sandbox Code Playgroud)

错误信息:

F:\react-boilerplate\app\store.js:49
      import('./reducers').then(function (reducerModule) {
      ^^^^^^
SyntaxError: Unexpected token import
Run Code Online (Sandbox Code Playgroud)

您可以在这里找到所有详细信息:https : //github.com/mxstbr/react-boilerplate/pull/1358

Dat*_*aya 6

安装babel-plugin-dynamic-import-node解决了我们的问题。此外,请确保babylonbabel依赖项)至少为6.12.0

另外,由于Travis缓存了node_modules旧版本babylon,因此我们在Travis构建方面遇到了问题:

$ npm ls babylon
react-boilerplate@3.3.0 /home/travis/build/mxstbr/react-boilerplate
??? babel-core@6.21.0
? ??? babylon@6.11.1
??? babel-eslint@7.1.1
? ??? babylon@6.14.1 
??? jest-cli@18.0.0
? ??? istanbul-lib-instrument@1.3.0
?   ??? babylon@6.14.1 
Run Code Online (Sandbox Code Playgroud)

,因此我们必须使用以下命令关闭缓存: cache: false