nan icon indicating copy to clipboard operation
nan copied to clipboard

nan 2.0.0 fails to build against node 0.10.x

Open rmoetwil opened this issue 11 years ago • 10 comments

nan 2.0.0 fails to build against node 0.10.x

Reason for this is the usage of v8::String::REPLACE_INVALID_UTF8 in nan.h. REPLACE_INVALID_UTF8 is not supported in node 0.10

E.g. when building sleep 3.0.0

> [email protected] install ...node_modules/sleep
> node-gyp rebuild

make: Entering directory `...node_modules/sleep/build'
  CXX(target) Release/obj.target/node_sleep/sleep.o
In file included from ../sleep.cc:2:0:
../node_modules/nan/nan.h: In constructor ‘Nan::Utf8String::Utf8String(v8::Local<v8::Value>)’:
../node_modules/nan/nan.h:1178:27: error: ‘REPLACE_INVALID_UTF8’ is not a member of ‘v8::String’
                           v8::String::REPLACE_INVALID_UTF8;

Apart from upgrading to node 0.12.x any ideas on how to resolve this?

rmoetwil avatar Aug 04 '15 11:08 rmoetwil

Use a supported version of Node 0.10 then. The current one is at 0.10.40. REPLACE_INVALID_UTF8 is available since 0.10.29.

kkoopa avatar Aug 04 '15 11:08 kkoopa

Ok. I was misled by the documentation, see https://v8docs.nodesource.com/node-0.10/d2/db3/classv8_1_1_string.html, which doesn't show the option.

But indeed I see the REPLACE_INVALID_UTF8 patch was applied in 0.10.29 and onwards.

rmoetwil avatar Aug 04 '15 12:08 rmoetwil

@rvagg why u no account for floating patches in the generated docs?

https://v8docs.nodesource.com/node-0.10/d4/da0/v8_8h_source.html#l01079 https://github.com/joyent/node/blob/v0.10.40/deps/v8/include/v8.h#L1079-L1083

kkoopa avatar Aug 04 '15 12:08 kkoopa

As a followup: This should no longer be a problem.

kkoopa avatar Aug 10 '15 14:08 kkoopa

There appear to be constellations where this is still an issue, for example, with g++ 4.6.3 (yes, this is old) and node v0.10.29. Is this to be expected?

root@beaglebone:~/dev# g++ --version
g++ (Debian 4.6.3-14) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
root@beaglebone:~/dev# node -v
v0.10.29
root@beaglebone:~/dev# npm install epoll
|
> [email protected] install /root/dev/node_modules/epoll
> node-gyp rebuild

make: Entering directory `/root/dev/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:316:47: error: ‘REPLACE_INVALID_UTF8’ is not a member of ‘v8::String’
cc1plus: warning: unrecognized command line option "-Wno-unused-local-typedefs" [enabled by default]
make: *** [Release/obj.target/epoll/src/epoll.o] Error 1
make: Leaving directory `/root/dev/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 3.8.13-bone70
gyp ERR! command "nodejs" "/usr/bin/node-gyp" "rebuild"
gyp ERR! cwd /root/dev/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! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] 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 3.8.13-bone70
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "epoll"
npm ERR! cwd /root/dev
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!     /root/dev/npm-debug.log
npm ERR! not ok code 0

fivdi avatar Aug 28 '15 14:08 fivdi

No, you cannot have 0.10.29, since it should have `REPLACE_INVALID_UTF8". Build from source against the bundled V8 and try again.

kkoopa avatar Aug 28 '15 20:08 kkoopa

It can happen if you have a node binary from your distro vendor that doesn't carry the REPLACE_INVALID_UTF8 patch, e.g. because it's linked against a shared libv8. In that case you're pretty much out of luck, you're going to have to use an official binary.

bnoordhuis avatar Aug 28 '15 20:08 bnoordhuis

Yes, that's it. The node binary is from the distro vendor and doesn't carry the REPLACE_INVALID_UTF8 patch. v8.h has the following:

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

rather that this:

  enum WriteOptions {
    NO_OPTIONS = 0,
    HINT_MANY_WRITES_EXPECTED = 1,
    NO_NULL_TERMINATION = 2,
    PRESERVE_ONE_BYTE_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
  };

Thank you very much for the information.

fivdi avatar Aug 28 '15 21:08 fivdi

I can suggest https://github.com/nodesource/distributions

kkoopa avatar Aug 28 '15 21:08 kkoopa

Excellent suggestion :+1:

I just installed v0.10.40 from NodeSource and everything is working as expected. Thanks again.

root@beaglebone:~# g++ --version
g++ (Debian 4.6.3-14) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


root@beaglebone:~# node -v
v0.10.40


root@beaglebone:~# npm install epoll
\
> [email protected] install /root/node_modules/epoll
> node-gyp rebuild

make: Entering directory `/root/node_modules/epoll/build'
  CXX(target) Release/obj.target/epoll/src/epoll.o
  SOLINK_MODULE(target) Release/obj.target/epoll.node
  SOLINK_MODULE(target) Release/obj.target/epoll.node: Finished
  COPY Release/epoll.node
make: Leaving directory `/root/node_modules/epoll/build'
[email protected] node_modules/epoll
├── [email protected]
└── [email protected]
root@beaglebone:~# 

fivdi avatar Aug 28 '15 21:08 fivdi