node.js - 开 Jest 和特拉维斯 CI, "SyntaxError: Unexpected strict mode reserved word"

标签 node.js travis-ci jestjs

我已经编写了一个 npm 模块,我正在尝试将其与 Travis CI 一起使用。我的测试是用 Jest 编写的,当我从本地命令行运行它们时,所有测试都通过了。

但是,当我将它们上传到 github ( https://github.com/jaysaurus/echo-handler ) 时,travis 运行我的代码并抛出以下异常:

0.69s$ npm test

> echo-handler@1.1.2 test /home/travis/build/jaysaurus/echo-handler

> jest __tests__/*.js

/home/travis/build/jaysaurus/echo-handler/node_modules/jest/node_modules/jest-cli/build/cli/index.js:1

sModule", { value: true });exports.runCLI = exports.run = undefined;let run = 

                                                                ^^^

SyntaxError: Unexpected strict mode reserved word
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/travis/build/jaysaurus/echo-handler/node_modules/jest/node_modules/jest-cli/bin/jest.js:13:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)

npm ERR! Test failed.  See above for more details.

我想知道我的构建是否意外地在/node_modules 中查找。 .gitignore 已设置为忽略/node_modules,我什至尝试将 package.json 设置为显式运行: "test": "jest __tests__/*.js", 但我仍然遇到相同的错误

这是 jest/Travis CI 上的 jest 版本/Travis CI 的 jest 实现中的错误吗?如果是这样,有解决方法吗?或者(更有可能)我错过了一些明显的事情?

最佳答案

您尚未在 .travis.yml 中指定 Node.js 版本看起来它有 installed version 0.10.48 。当时 let 不受支持,当您尝试使用此类保留字之一时(至少在严格模式下),它会抛出错误。

您应该始终specify the Node.js versions你想运行它。

例如,如果您只想在最新的 8.x 版本上运行它,则可以使用以下配置:

language: node_js
node_js:
  - "8"

关于node.js - 开 Jest 和特拉维斯 CI, "SyntaxError: Unexpected strict mode reserved word",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46767645/

相关文章:

javascript - NodeJs Express 路线不工作

c# - 如何使用 Travis CI 构建混合 (C++ + C#) 解决方案?

javascript - Jest mock redux-store getState() 在带有 redux-mock-store 的模块中使用

javascript - 覆盖 jest-junit 默认输出位置?

javascript - 单元测试 Controller 使用 Jest、NodeJS

javascript - 使用 await 在 try/catch block 中声明一个 const

javascript - 在 Node.js 中的文件之间共享变量?

mysql - 特拉维斯 : how to run tests against different MySQL backends?

github - RStudio 和 Travis CI 构建检查不匹配 (libudunits2.so)

node.js - 'Express' 不是识别命令(Windows)