开玩笑的设置"SyntaxError:意外的令牌导出" [英] Jest setup "SyntaxError: Unexpected token export"

查看:440
本文介绍了开玩笑的设置"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)"
]

这篇关于开玩笑的设置"SyntaxError:意外的令牌导出"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆