Node.js v0.10.29 and native addons on the Raspberry Pi

Brian Cooke edited this page Jan 14, 2017 · 10 revisions

There are issues with the version of Node.js v0.10.29 that comes preinstalled with Raspbian Jessie 2015-11-21 or newer. It's not possible to install Node.js native add-ons or packages that depend on native add-ons. Attempting to do so will result in a compile error stating that ‘REPLACE_INVALID_UTF8’ is not a member of ‘v8::String’. For example, npm install onoff will result in the following output:

pi@raspberrypi:~/onoff $ node -v
v0.10.29
pi@raspberrypi:~/onoff $ npm -v
1.4.21
pi@raspberrypi:~/onoff $ npm install onoff
/
> epoll@0.1.16 install /home/pi/onoff/node_modules/onoff/node_modules/epoll
> node-gyp rebuild

make: Entering directory '/home/pi/onoff/node_modules/onoff/node_modules/epoll/build'
  CXX(target) Release/obj.target/epoll/src/epoll.o
In file included from ../src/epoll.cc:15:0:
../node_modules/nan/nan.h:328:47: error: ‘REPLACE_INVALID_UTF8’ is not a member of ‘v8::String’
   static const unsigned kReplaceInvalidUtf8 = v8::String::REPLACE_INVALID_UTF8;
                                               ^
epoll.target.mk:84: recipe for target 'Release/obj.target/epoll/src/epoll.o' failed
make: *** [Release/obj.target/epoll/src/epoll.o] Error 1
make: Leaving directory '/home/pi/onoff/node_modules/onoff/node_modules/epoll/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/share/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:809:12)
gyp ERR! System Linux 4.1.13-v7+
gyp ERR! command "nodejs" "/usr/bin/node-gyp" "rebuild"
gyp ERR! cwd /home/pi/onoff/node_modules/onoff/node_modules/epoll
gyp ERR! node -v v0.10.29
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok 
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

npm ERR! epoll@0.1.16 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the epoll@0.1.16 install script.
npm ERR! This is most likely a problem with the epoll package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls epoll
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 4.1.13-v7+
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "onoff"
npm ERR! cwd /home/pi/onoff
npm ERR! node -v v0.10.29
npm ERR! npm -v 1.4.21
npm ERR! code ELIFECYCLE
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/pi/onoff/npm-debug.log
npm ERR! not ok code 0
pi@raspberrypi:~/onoff $ 

Additional Information

Further details as to why this issues occurs can be found on the Raspberry Pi forum.

Solution

To resolve this issue, install Node.js binaries from a source such as the Node.js Foundation or NodeSource.

The latest Node.js ARMv6 binaries for the Raspberry Pi Zero or 1 and ARMv7 binaries for the Raspberry Pi 2 or 3 from the Node.js Foundation can be found here. Additional ARMv6 and ARMv7 binaries for Node.js v4.0.0 or higher can be found in the correspondingly named directory here.

Installation instructions for Node.js ARMv7 binaries for the Raspberry Pi 2 or 3 from NodeSource can be found here.

Workaround

There is a Debian Unstable patch that is disputed for fixing the issue. This patch can be manully applied by replacing the following snippet of code in /usr/include/nodejs/deps/v8/include/v8.h:

  enum WriteOptions {
    NO_OPTIONS = 0,
    HINT_MANY_WRITES_EXPECTED = 1,
    NO_NULL_TERMINATION = 2,
    PRESERVE_ASCII_NULL = 4,
  };

with:

  enum WriteOptions {
    NO_OPTIONS = 0,
    HINT_MANY_WRITES_EXPECTED = 1,
    NO_NULL_TERMINATION = 2,
    PRESERVE_ASCII_NULL = 4,
    REPLACE_INVALID_UTF8 = 0
  };

Note that /usr/include/nodejs/deps/v8/include/v8.h will not exits if npm hasn't been installed.