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

查看:27
本文介绍了玩笑设置“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/"
    ]
  }

这看起来像是一个 hack,因为运行一个导入 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.

推荐答案

我不得不将它添加到我的 .jestconfig 中:

I had to add this into my .jestconfig:

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

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

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