NodeJS unstable: unable to npm-install modules that need compilation?

139 views
Skip to first unread message

~flow

unread,
Sep 21, 2013, 12:22:50 PM9/21/13
to nod...@googlegroups.com
(this is a copy of http://stackoverflow.com/questions/18921405/nodejs-unstable-unable-to-npm-install-modules-that-need-compilation)

i've been working with NodeJS 0.11.x distros for some time now, mainly because i believe that generators and the yield statement bring big advances in terms of asynchronous manageability (see coffy-script and suspend).

that said, there's a serious setback when running bleeding-edge, unstable NodeJS installs: when doing npm install xy-module, gyp will fail (always? sometimes?) when trying to compile any C components.

is there a general reason this must be so? is there any trick / patch / configuration i can apply to remedy the situation? if a given module does compile on NodeJS 0.10.x, but fails on 0.11.x, should i expect it to compile on 0.12.x as soon as that becomes available?


thanks for sharing any thoughts.


mscdex

unread,
Sep 21, 2013, 1:05:56 PM9/21/13
to nod...@googlegroups.com
On Saturday, September 21, 2013 12:22:50 PM UTC-4, ~flow wrote:
is there a general reason this must be so? is there any trick / patch / configuration i can apply to remedy the situation? if a given module does compile on NodeJS 0.10.x, but fails on 0.11.x, should i expect it to compile on 0.12.x as soon as that becomes available?

The reason is that there are v8 API changes in master since v0.10.x.

~flow

unread,
Sep 21, 2013, 1:22:45 PM9/21/13
to nod...@googlegroups.com
so the failure to compile is not inherent to an unstable node distro, it's just a (rather pervasive) accident of the API that a given module happens to use, right?

this seems to imply that many unmaintained modules will not be available in 0.12 unless fixes get published.

is there any guide how to migrate C code from 0.10 to 0.11 and on?

Ben Noordhuis

unread,
Sep 21, 2013, 1:37:45 PM9/21/13
to nod...@googlegroups.com
The two main changes are as follows:

* Persistent<T> no longer derives from Handle<T>. To recreate the
Handle from a Persistent, call Local<T>::New(isolate, persistent).
You can obtain the isolate with Isolate::GetCurrent() (but note that
Isolate::GetCurrent() will probably go away in newer versions of V8.)

* The prototype of C++ callbacks and accessors has changed. Before,
your function looked like this:

Handle<Value> MyCallback(const Arguments& args) {
HandleScope handle_scope;
/* Do useful work, then: */
return handle_scope.Close(Integer::New(42));
/* Or: */
return handle_scope.Close(String::New("hello"));
/* Or: */
return Null();
}

In v0.11 and v0.12 that becomes:

void MyCallback(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
HandleScope handle_scope(isolate);
/* Do useful work, then: */
args.GetReturnValue().Set(42);
/* Or: */
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "hello"));
/* Or: */
args.GetReturnValue().SetNull();
}

There have been more changes but these two impact every native add-on.

~flow

unread,
Sep 21, 2013, 2:05:17 PM9/21/13
to nod...@googlegroups.com
thanks a lot!

Rod Vagg

unread,
Sep 21, 2013, 7:20:44 PM9/21/13
to nod...@googlegroups.com
Have a listen to the latest NodeUp, #52 is about exactly this topic. http://nodeup.com/fiftytwo

~flow

unread,
Sep 24, 2013, 8:02:02 AM9/24/13
to nod...@googlegroups.com
just did a napping session with that one. good to know i'm not alone.

good to know there's something being done by someone, too:

https://github.com/rvagg/nan

Native Abstractions for Node.js

A header file filled with macro and utility goodness for making addon development for Node.js easier across versions 0.8, 0.10 and 0.11, and eventually 0.12.

Reply all
Reply to author
Forward
0 new messages