0

grunt test在我的源代码 Github/Codeship 中运行时,我发现了以下错误。

在 codeship 内的 setup 命令中,以下代码是这样配置的。

nvm install 0.12.6
nvm use 0.12.6
npm install grunt-cli bower -g
npm install
bower install -p
npm run update-webdriver

并在 codeship 中测试命令;

grunt test

但是在我的源代码中找不到该错误,实际上是通过查看 codeship 给出的以下错误消息在 github/codeship 中找到的。因为这些文件夹结构没有像我们在服务器中配置的那样定义。请帮助我如何解决它。谢谢。

Using 2 x hasMany to represent N:M relations has been deprecated. Please use belongsToMany instead
>> Mocha exploded!
>> /home/rof/src/github.com/MyProjects/node_modules/sparkpost/node_modules/request/node_modules/hawk/node_modules/boom/lib/index.js:5
>> const Hoek = require('hoek');
>> ^^^^^
>> SyntaxError: Use of const in strict mode.
>>     at exports.runInThisContext (vm.js:73:16)
>>     at Module._compile (module.js:443:25)
>>     at Object.Module._extensions..js (module.js:478:10)
>>     at Module.load (module.js:355:32)
>>     at Function.Module._load (module.js:310:12)
>>     at Module.require (module.js:365:17)
>>     at require (module.js:384:17)
>>     at Object.<anonymous> (/home/rof/src/github.com/MyProjects/node_modules/sparkpost/node_modules/request/node_modules/hawk/lib/index.js:5:33)
>>     at Module._compile (module.js:460:26)
>>     at Object.Module._extensions..js (module.js:478:10)
>>     at Module.load (module.js:355:32)
>>     at Function.Module._load (module.js:310:12)
>>     at Module.require (module.js:365:17)
>>     at require (module.js:384:17)
>>     at Object.<anonymous> (/home/rof/src/github.com/MyProjects/node_modules/sparkpost/node_modules/request/request.js:9:12)
>>     at Module._compile (module.js:460:26)
Warning: Task "mochaTest:src" failed. Use --force to continue.
4

2 回答 2

5

因为这些文件夹结构没有像我们在服务器中配置的那样定义。

此问题与文件夹结构无关。

您的项目当前使用0.12.6的是非常过时的 Node 版本。Node 的当前 LTS 版本是6.11.3,当前版本是8.6.0.

具体问题是SyntaxError: Use of const in strict mode.这意味着您正在使用的库当前正在使用 ES2015 语法或更高版本。问题的根本原因在于Boom模块,它const在第 5 行使用(很可能还有其他当前语法)。

您的问题的解决方案是更新 Codeship 中使用的节点版本。

nvm install 6.11.3
nvm use 6.11.3
于 2017-10-02T13:03:42.847 回答
2

简单的方法。只需通过以下代码升级您的节点:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

请享用!

于 2018-04-24T08:10:02.747 回答