TravisCI在使用Node BCrypt时出现node-gyp错误

5
我正在尝试让我的Node.js 7项目在TravisCI上运行。 在本地一切正常,但是当Travis试图测试该项目时,我会收到以下错误信息:
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/home/travis/.nvm/versions/node/v6.9.1/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Linux 4.8.7-040807-generic
gyp ERR! command "/home/travis/.nvm/versions/node/v6.9.1/bin/node" "/home/travis/.nvm/versions/node/v6.9.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/travis/build/actuallymentor/react-node-boilerplate/node_modules/bcrypt
gyp ERR! node -v v6.9.1
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok 

并且:

npm ERR! bcrypt@0.8.7 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the bcrypt@0.8.7 install script 'node-gyp rebuild'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the bcrypt package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild

这会导致我的构建在运行测试之前失败。
2个回答

6
这里的问题在于bcrypt需要使用c++库,而Travis上没有安装。为了让它正常工作,我们需要:
  1. 安装这个库
  2. 设置一个环境变量,指示我们要使用它
另外,node-gyp喜欢被全局安装,所以我们可以一次性进行配置。
在你的.travis.yml文件中添加:
sudo: required
before_install:
  - npm install -g node-gyp
addons:
  apt:
    sources:
    - ubuntu-toolchain-r-test
    packages:
    - g++-5

此外,请确保在您的Travis项目设置中设置此环境变量:
CXX=g++-5

请注意,任何高于4.8版本的g++都应该可以工作。

0
这对我来说没问题!!!
在travis上使用nodejs 4.6.2和bcryp 1.0.1。
env:
  - CXX=g++-4.8
addons:
  apt:
    sources:
    - ubuntu-toolchain-r-test
    packages:
    - g++-4.8

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接