Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TravisCI failing on Node BCrypt with node-gyp errors

I am trying to get my Node.js 7 project working on TravisCI. Everything works locally but when travis attempts to test the project I get:

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 

And:

npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] 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

This causes my build to fail even before running tests.

like image 589
Mentor Avatar asked Nov 25 '16 10:11

Mentor


1 Answers

The issue here is that bcrypt required the use of a c++ library. Travis does not have this installed. To make it work we need to:

  1. Install the library
  2. Set an environment variable indicating we want to use it

Additionally node-gyp likes to be installed globally so we can configure that as well in one go.

In your .travis.yml put:

sudo: required
before_install:
  - npm install -g node-gyp
addons:
  apt:
    sources:
    - ubuntu-toolchain-r-test
    packages:
    - g++-5

Also, be sure to in your travis project settings set this environment variable:

CXX=g++-5

Note that any g++ version above 4.8 should work.

like image 89
Mentor Avatar answered Nov 15 '22 05:11

Mentor