开玩笑的设置"SyntaxError:意外的令牌导出"

问题描述:

我正在将测试实施到当前没有测试的现有项目中.我的测试无法编译node_modules/导入.

I'm implementing tests into an existing project that currently has no tests. My tests are failing to compile node_modules/ imports.

/Users/me/myproject/node_modules/lodash-es/lodash.js:10
export { default as add } from './add.js';
^^^^^^
SyntaxError: Unexpected token export

  at transformAndBuildScript (node_modules/jest-runtime/build/transform.js:320:12)
  at Object.<anonymous> (app/reducers/kind_reducer.js:2:43)
  at Object.<anonymous> (app/reducers/index.js:12:47)

我发现的解决方法是将package.json jest配置中的白名单" node_modules像这样:

The workaround I've found is to 'whitelist' node_modules in package.json jest config like this:

"jest": {
    "transformIgnorePatterns": [
      "!node_modules/"
    ]
  }

这似乎是一种黑客,因为运行导入node_modules/lodash-es/lodash.js的简单测试需要1分钟以上的时间.

This seems like a hack because it takes over 1 minute to run a simple test that imports node_modules/lodash-es/lodash.js.

感谢您的帮助或指导,谢谢!

Any help or direction is appreciate, thanks!

我必须将此添加到我的.jestconfig:

I had to add this into my .jestconfig:

"transformIgnorePatterns": [
  "<rootDir>/node_modules/(?!lodash-es)"
]