admin管理员组

文章数量:1294384

I'm using the code splitting feature of webpack, but it seems that jest doesn't recognize the import() function:

        import('myModule').then(function (myModule) {
        ^^^^^^
SyntaxError: Unexpected token import

I don't have any special setup. My npm test script is simply run jest "test": "jest"

How can I make it work?

I'm using the latest version of jest 20.0.4 and babel-jest 20.0.3

I'm using the code splitting feature of webpack, but it seems that jest doesn't recognize the import() function:

        import('myModule').then(function (myModule) {
        ^^^^^^
SyntaxError: Unexpected token import

I don't have any special setup. My npm test script is simply run jest "test": "jest"

How can I make it work?

I'm using the latest version of jest 20.0.4 and babel-jest 20.0.3

Share Improve this question asked Jun 20, 2017 at 3:25 CodinCatCodinCat 15.9k6 gold badges50 silver badges63 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

Oh I just found the answer.

Simply install this plugin: https://github./airbnb/babel-plugin-dynamic-import-node and add it to the .babelrc file:

{
  ...
  "env": {
    "test": {
      "plugins": ["dynamic-import-node"]
    }
  }
}

本文标签: javascriptCode splitting import breaks Jest testsStack Overflow