fivdi
Posts: 445
Joined: Sun Sep 23, 2012 8:09 pm
Contact: Website

Node.js v0.10.29 broken in Raspbian Jessie 2015-11-21

Fri Dec 04, 2015 10:58 am

The variant of Node.js v0.10.29 that comes preinstalled with Raspbian Jessie 2015-11-21 is broken. It's not possible to install Node.js native add-ons with this variant of Node.js.

The symptoms of this issue can be seen when installing Node.js native add-ons or packages that depend on native add-ons.

For example, below is the output of "npm install onoff". The onoff package depends on the native add-on epoll. As can be seen, there is a compile error stating that "‘REPLACE_INVALID_UTF8’ is not a member of ‘v8::String’" when the epoll native add-on is compiled.

Code: Select all

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.1.13-v7+ #826 SMP PREEMPT Fri Nov 13 20:19:03 GMT 2015 armv7l GNU/Linux
pi@raspberrypi:~ $ node -v
v0.10.29
pi@raspberrypi:~ $ npm -v
1.4.21
pi@raspberrypi:~ $ npm install onoff
/
> epoll@0.1.16 install /home/pi/node_modules/onoff/node_modules/epoll
> node-gyp rebuild

make: Entering directory '/home/pi/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/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/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
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/npm-debug.log
npm ERR! not ok code 0
pi@raspberrypi:~ $ 
The source of this issue is a patch called REPLACE_INVALID_UTF8 which was applied to the official Node.js v0.10.29 codebase, but not to the codebase being used to build Raspbian Jessie.

The official Node.js v0.10.29 codebase contains the following snippet of code in v8.h:

Code: Select all

  enum WriteOptions {
    NO_OPTIONS = 0,
    HINT_MANY_WRITES_EXPECTED = 1,
    NO_NULL_TERMINATION = 2,
    PRESERVE_ASCII_NULL = 4,
    // Used by WriteUtf8 to replace orphan surrogate code units with the
    // unicode replacement character. Needs to be set to guarantee valid UTF-8
    // output.
    REPLACE_INVALID_UTF8 = 8
  };
The corresponding snippet of code in /usr/include/nodejs/deps/v8/include/v8.h on a Raspbian Jessie 2015-11-21 installation is:

Code: Select all

  enum WriteOptions {
    NO_OPTIONS = 0,
    HINT_MANY_WRITES_EXPECTED = 1,
    NO_NULL_TERMINATION = 2,
    PRESERVE_ASCII_NULL = 4
  };
As can be seen, REPLACE_INVALID_UTF8 is missing on Raspbian Jessie 2015-11-21.

To the best of my knowledge the corresponding Debian patch can be found at
https://sources.debian.net/src/libv8-3. ... TF8.patch/

Can Raspbian Jessie be updated to include this patch?

fivdi
Posts: 445
Joined: Sun Sep 23, 2012 8:09 pm
Contact: Website

Re: Node.js v0.10.29 broken in Raspbian Jessie 2015-11-21

Fri Dec 04, 2015 11:36 am

Note that it's possible to workaround this issue by replacing the following snippet of code in /usr/include/nodejs/deps/v8/include/v8.h:

Code: Select all

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

Code: Select all

  enum WriteOptions {
    NO_OPTIONS = 0,
    HINT_MANY_WRITES_EXPECTED = 1,
    NO_NULL_TERMINATION = 2,
    PRESERVE_ASCII_NULL = 4,
    REPLACE_INVALID_UTF8 = 0
  };
Edit: fixed a typo (changed REPLACE_INVALID_UTF8 = 8 to REPLACE_INVALID_UTF8 = 0)

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Node.js v0.10.29 broken in Raspbian Jessie 2015-11-21

Fri Dec 04, 2015 2:56 pm

it is possible to upgrade to a later version:
Using newer versions of node.js

This pre-install uses the default node.js within Debian Jessie, which is version 0.10.29. You may wish to use more recent versions of Node.js such as v0.12.x or v4.2.x

To do this you must uninstall the built-in version and re-install using the instructions below. To uninstall:

Code: Select all

sudo apt-get remove nodered
sudo apt-get remove nodejs nodejs-legacy
sudo apt-get remove npm   # if you installed npm
This will remove all the built in packages but leave your workspace - by default at ~/.node-red . You may then proceed to re-install as per instructions below.

fivdi
Posts: 445
Joined: Sun Sep 23, 2012 8:09 pm
Contact: Website

Re: Node.js v0.10.29 broken in Raspbian Jessie 2015-11-21

Fri Dec 04, 2015 4:45 pm

I realize that it's possible to install newer versions of Node.js and in general that's what I do.

The point that I want to make here is that Jessie comes with Node.js v0.10.29 preinstalled but can't be used to install native add-ons. This will be a poor user experience for a large percentage of people attempting to install such modules. On the other hand, the issue is relatively easy to fix and I was hoping that the version that's preinstalled on Jessie could be updated to include the fix.

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Node.js v0.10.29 broken in Raspbian Jessie 2015-11-21

Fri Dec 04, 2015 5:09 pm

fivdi wrote:I realize that it's possible to install newer versions of Node.js and in general that's what I do.

The point that I want to make here is that Jessie comes with Node.js v0.10.29 preinstalled but can't be used to install native add-ons. This will be a poor user experience for a large percentage of people attempting to install such modules. On the other hand, the issue is relatively easy to fix and I was hoping that the version that's preinstalled on Jessie could be updated to include the fix.
I think this version was included to support Node-RED across all hardware revisions.

fivdi
Posts: 445
Joined: Sun Sep 23, 2012 8:09 pm
Contact: Website

Re: Node.js v0.10.29 broken in Raspbian Jessie 2015-11-21

Fri Dec 04, 2015 5:21 pm

I think this version was included to support Node-RED across all hardware revisions.
Perhaps. However, if it was fixed to include the patch mentioned above, it would not only support Node-RED across all hardware revisions, but a lot of other modules too, for example, epoll, i2c-bus, onoff, pigpio, and many many more ...

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Node.js v0.10.29 broken in Raspbian Jessie 2015-11-21

Fri Dec 04, 2015 6:00 pm

fivdi wrote:
I think this version was included to support Node-RED across all hardware revisions.
Perhaps. However, if it was fixed to include the patch mentioned above, it would not only support Node-RED across all hardware revisions, but a lot of other modules too, for example, epoll, i2c-bus, onoff, pigpio, and many many more ...
NR was pinned to v0.10.x for a very long time, and has only recently moved on.

The foundation aren't responsible for NR, so go here to suggest how they should 'fix' it (without breaking the hundreds of NR flows in the process).

You had to install npm, so as the 'phrase of the week' says: what you want 'is only an apt-get away'

fivdi
Posts: 445
Joined: Sun Sep 23, 2012 8:09 pm
Contact: Website

Re: Node.js v0.10.29 broken in Raspbian Jessie 2015-11-21

Sat Dec 05, 2015 7:10 am

The issue isn't related to Node-RED, it's a Node.js issue.

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Node.js v0.10.29 broken in Raspbian Jessie 2015-11-21

Sat Dec 05, 2015 11:09 am

fivdi wrote:The issue isn't related to Node-RED, it's a Node.js issue.
Yes it is, as this is the first time that node.js has been included as it is required for NR.

User avatar
joan
Posts: 15623
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Node.js v0.10.29 broken in Raspbian Jessie 2015-11-21

Sat Dec 05, 2015 11:19 am

Is this a bug in Raspbian or the Raspberry Pi image? If it's a Raspbian bug it may get fixed in a normal Debian update.

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Node.js v0.10.29 broken in Raspbian Jessie 2015-11-21

Sat Dec 05, 2015 11:40 am

joan wrote:Is this a bug in Raspbian or the Raspberry Pi image? If it's a Raspbian bug it may get fixed in a normal Debian update.
It's not a bug, just a legacy version of node.js that was included for NR support, and wasn't present in previous releases of raspbian. It doesn't take much effort to remove and upgrade it, but some people just like to moan.

User avatar
joan
Posts: 15623
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Node.js v0.10.29 broken in Raspbian Jessie 2015-11-21

Sat Dec 05, 2015 11:44 am

asandford wrote:
joan wrote:Is this a bug in Raspbian or the Raspberry Pi image? If it's a Raspbian bug it may get fixed in a normal Debian update.
It's not a bug, just a legacy version of node.js that was included for NR support, and wasn't present in previous releases of raspbian. It doesn't take much effort to remove and upgrade it, but some people just like to moan.
It sounds like a bug to me. It stops the proper operation of software. But the word used is irrelevant. It seems sensible to correct the "whatever" as near to the source as possible.

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Node.js v0.10.29 broken in Raspbian Jessie 2015-11-21

Sat Dec 05, 2015 12:07 pm

joan wrote: It sounds like a bug to me. It stops the proper operation of software. But the word used is irrelevant. It seems sensible to correct the "whatever" as near to the source as possible.
The software that node.js was introduced for is NR, and that works fine. For a long time 0.10.x was the only ARM6 version available from http://node-arm.herokuapp.com/ (0.12.6 is the latest)

As an aside, npm wasn't included in the distro as it drags in a huge amount of other stuff, but NR doesn't require any other packages to be useful.

fivdi
Posts: 445
Joined: Sun Sep 23, 2012 8:09 pm
Contact: Website

Re: Node.js v0.10.29 broken in Raspbian Jessie 2015-11-21

Sat Dec 05, 2015 5:53 pm

joan wrote:It sounds like a bug to me. It stops the proper operation of software. But the word used is irrelevant. It seems sensible to correct the "whatever" as near to the source as possible.
I agree.

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Node.js v0.10.29 broken in Raspbian Jessie 2015-11-21

Sat Dec 05, 2015 7:55 pm

fivdi wrote:
joan wrote:It sounds like a bug to me. It stops the proper operation of software. But the word used is irrelevant. It seems sensible to correct the "whatever" as near to the source as possible.
I agree.
How does using features that don't exist in the version of the software installed count as a bug? , user error perhaps, but not a bug. Upgrade node.js if you need the extra functionality in 0.12.x and v4 (you had to install npm, why is it suddenly such a chore to install a version of node.js that you need?). The rest of us who have been using NR for years are happy that it's now supported in the distro, but I'm surprised that such an old version was used as NR now runs on 0.12 on all hardware.

Remember that node.js was supplied purely for NR to function, it wasn't before as it's trivial to install if you need it.

fivdi
Posts: 445
Joined: Sun Sep 23, 2012 8:09 pm
Contact: Website

Re: Node.js v0.10.29 broken in Raspbian Jessie 2015-11-21

Sat Dec 05, 2015 10:24 pm

I think there's a terrible misunderstanding here. My goal here is actually quite selfless. That goal is to improve the user experience for people that would like to use Node.js on the Raspberry Pi, irrespective of their knowledge level. Raspbian Jessie now comes with Node.js preinstalled and that's good. Raspbian Jessie Lite doesn't come with Node.js prinstalled, but the following commands will install both Node.js and npm:

Code: Select all

sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm
sudo apt-get install nodejs-legacy
For what ever reason, it's Node.js v0.10.29, but that's not important. What is important is that one line of code is missing in a header file (/usr/include/nodejs/deps/v8/include/v8.h.) The fact that this line of code is missing makes it impossible to install native add-ons. If the Debian patch linked to in the original post above was applied to the Raspbian Jessie codebase, it would be possible to install native add-ons. This would be a major boost in user experience, particularly for beginners.

The symptom of this issue is the following compiler error:

error: ‘REPLACE_INVALID_UTF8’ is not a member of ‘v8::String’

Note that we are talking about Node.js here and people who code in JavaScript. Many of these people know little or nothing about C++. When confronted with this error message, it will mean absolutely nothing to them. In fact, this error message will mean little or nothing to most C++ developers.

The first time I was confronted with this issue it took me many many hours to figure out what the problem actually was. At the time, it was on the BeagleBone Black. Here are two of the related issues:

https://github.com/RobertCNelson/omap-i ... /issues/61
https://github.com/nodejs/nan/issues/394

Many people will actually ditch Node.js when confronted with this error message. They will assume that Node.js is junk or that the add-on that they are attempting to install is junk and simply ditch it. They will not automatically assume that they need to upgrade their Node.js version. My only goal here is to prevent these people form ditching Node.js.
asandford wrote:
fivdi wrote:
joan wrote:It sounds like a bug to me. It stops the proper operation of software. But the word used is irrelevant. It seems sensible to correct the "whatever" as near to the source as possible.
I agree.
How does using features that don't exist in the version of the software installed count as a bug? , user error perhaps, but not a bug. Upgrade node.js if you need the extra functionality in 0.12.x and v4 (you had to install npm, why is it suddenly such a chore to install a version of node.js that you need?). The rest of us who have been using NR for years are happy that it's now supported in the distro, but I'm surprised that such an old version was used as NR now runs on 0.12 on all hardware.

Remember that node.js was supplied purely for NR to function, it wasn't before as it's trivial to install if you need it.
@asandford: I actually regard you attitude as hostile, unfriendly, and unconstructive. I also feel that you have been misinformed.

Node.js is not being supplied purely for Node-RED to function. It's being supplied for everyone, irrespective of whether they use Node-RED or not. This can be clearly seen by starting with Raspbain Jessie Lite and executing the four commands above to install Node.js and npm.

Also, I don't use Node.js v0.10.29. I currently use v5.1.0 on the Pi and I have no problems installing it and it's not a chore for me to install it. However, figuring out how to install v5.1.0 or any other version is not trivial the first time you need to do it. This is also where some people will ditch Node.js and another reason why it makes sense to apply the patch that it would make it possible to install add-ons with Node.js v0.10.29 on Raspbian Jessie or Jessie Lite.

diederik
Posts: 394
Joined: Wed Mar 26, 2014 11:17 pm

Re: Node.js v0.10.29 broken in Raspbian Jessie 2015-11-21

Sun Dec 06, 2015 2:41 am

fivdi wrote:The variant of Node.js v0.10.29 that comes preinstalled with Raspbian Jessie 2015-11-21 is broken. It's not possible to install Node.js native add-ons with this variant of Node.js.
...
As can be seen, REPLACE_INVALID_UTF8 is missing on Raspbian Jessie 2015-11-21.

To the best of my knowledge the corresponding Debian patch can be found at
https://sources.debian.net/src/libv8-3. ... TF8.patch/

Can Raspbian Jessie be updated to include this patch?
That patch is included and disputed in Debian Unstable and as such it will not be included in Raspbian Jessie.
If you want to get it fixed in Raspbian Jessie, you'd have to work to get it fixed in Debian Jessie first by notifying the Debian maintainer that the Jessie version is also affected and convincing him/her that it is so important that it should be included in the current Debian Stable too. If you succeed in that, then it will 'propagate' to Raspbian Jessie too.
Warning: this will not be easy.

fivdi
Posts: 445
Joined: Sun Sep 23, 2012 8:09 pm
Contact: Website

Re: Node.js v0.10.29 broken in Raspbian Jessie 2015-11-21

Sun Dec 06, 2015 8:58 am

diederik wrote:
fivdi wrote:The variant of Node.js v0.10.29 that comes preinstalled with Raspbian Jessie 2015-11-21 is broken. It's not possible to install Node.js native add-ons with this variant of Node.js.
...
As can be seen, REPLACE_INVALID_UTF8 is missing on Raspbian Jessie 2015-11-21.

To the best of my knowledge the corresponding Debian patch can be found at
https://sources.debian.net/src/libv8-3. ... TF8.patch/

Can Raspbian Jessie be updated to include this patch?
That patch is included and disputed in Debian Unstable and as such it will not be included in Raspbian Jessie.
If you want to get it fixed in Raspbian Jessie, you'd have to work to get it fixed in Debian Jessie first by notifying the Debian maintainer that the Jessie version is also affected and convincing him/her that it is so important that it should be included in the current Debian Stable too. If you succeed in that, then it will 'propagate' to Raspbian Jessie too.
Warning: this will not be easy.
That's unfortunate. I somehow have the feeling that would be a long drawn out undertaking with little chance of success. Node.js v0.10 is an LTS release that will be maintained until October 2016. I probably wouldn't be able to convince them by then.

On the other hand, maybe the patch could be applied to Raspbian only.

Alternative, perhaps it would be better if Raspbian used alternative Node.js binaries in the future. The Node.js Foundation provide ARMv6, ARMv7, and ARMv8 Node.js binaries for Node.js v4.0 and higher. For example, see https://nodejs.org/dist/v4.0.0/ or https://nodejs.org/dist/v5.1.1/. The ARMv6 binaries function on both the Pi 1 and the Pi 2.

Return to “Raspberry Pi OS”