Tags

, ,

Upon deploying your node.js app using Travis CI you may encountered a build error that says “This version of node/NAN/v8 requires a C++11 compiler” it means that the current compiler is not capable to build to some node modules like json or time.
See below the log:

Starting with io.js 3 and Node.js 4, building native extensions requires C++11-compatible compiler, which seems unavailable on this VM. Please read https://docs.travis-ci.com/user/languages/javascript-with-nodejs#Node.js-v4-(or-io.js-v3)-compiler-requirements.
$ node --version
v4.4.5
$ npm --version
2.15.5
$ nvm --version
0.31.0
$ npm install 
npm WARN deprecated jade@1.9.2: Jade has been renamed to pug, please install the latest version of pug instead of jade
npm WARN deprecated transformers@2.1.0: Deprecated, use jstransformer
> time@0.11.4 install /home/travis/build/sudogem/microblog-express-node/node_modules/time
> node-gyp rebuild
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
make: Entering directory `/home/travis/build/sudogem/microblog-express-node/node_modules/time/build'
  CXX(target) Release/obj.target/time/src/time.o
In file included from ../src/time.cc:5:0:
../node_modules/nan/nan.h:43:3: error: #error This version of node/NAN/v8 requires a C++11 compiler

Solution:
In your .travis.yml add the script below:

language: node_js
node_js: stable
before_install:
  - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
  - sudo apt-get -qq update
  - sudo apt-get -qq install g++-4.8
env:
  - CXX=g++-4.8
notifications: ## Here we add a slack notifications once the deployment is completed. Refer to Slack Travis integration
  slack: mycompany:QW93JOP898JEIQWJDSXW13IOK

If the above script don’t work use this one:

sudo: false
env:
  - CXX=g++-4.8
language: node_js
node_js:
  - "4"
addons:
  apt:
    sources:
    - ubuntu-toolchain-r-test
    packages:
    - gcc-4.8
    - g++-4.8

Thats it!

References:
https://github.com/PacificBiosciences/pbdagcon/pull/7
https://github.com/travis-ci/travis-ci/issues/1379
http://stackoverflow.com/questions/22111549/travis-ci-with-clang-3-4-and-c11

Advertisements