audreyt / node-webworker-threads

Lightweight Web Worker API implementation with native threads
https://npmjs.org/package/webworker-threads
Other
2.3k stars 149 forks source link

Do not work with Node.js v9.0.0 #169

Closed ndaidong closed 6 years ago

ndaidong commented 7 years ago

Hello,

I got the following error after upgrading Node.js to v9.0.0:

/var/www/projects/news-loader/node_modules/natural/lib/natural/classifiers/classifier.js:32
    if (e.code !== 'MODULE_NOT_FOUND') throw e;
                                       ^

Error: The module '/var/www/projects/news-loader/node_modules/webworker-threads/build/Release/WebWorkerThreads.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 57. This version of Node.js requires
NODE_MODULE_VERSION 59. Please try re-compiling or re-installing

The issue happened within natural's classifier module, where I founded:

try {
    var Threads = require('webworker-threads');
} catch (e) {
    // Since webworker-threads are optional, only thow if the module is found
    if (e.code !== 'MODULE_NOT_FOUND') throw e;
}

It looks like the module webworker-threads could not be imported here because it was built with C++ and an older Node.js version as the log written. How I can fix this?

Thank you.

fivdi commented 7 years ago

It looks like the module webworker-threads could not be imported here because it was built with C++ and an older Node.js version as the log written. How I can fix this?

It looks like webworker-threads was installed with Node 8.x but at runtime Node 9 is used. Try reinstalling webworker-threads with Node 9 to see if it works.

ndaidong commented 7 years ago

@fivdi : I've tried. After I removed node_modules and installed again, it throws an error and aborts the process.

ndaidong@bella-mint /var/www/projects/news-loader $ npm i webworker-threads
npm WARN npm npm does not support Node.js v9.0.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8.
npm WARN npm You can find the latest version at https://nodejs.org/
/usr/local/bin/node[26267]: ../src/node_zlib.cc:430:static void node::{anonymous}::ZCtx::Init(const v8::FunctionCallbackInfo<v8::Value>&): Assertion `args.Length() == 7 && "init(windowBits, level, memLevel, strategy, writeResult, writeCallback," " dictionary)"' failed.
 1: node::Abort() [npm]
 2: node::Assert(char const* const (*) [4]) [npm]
 3: 0x12beb2a [npm]
 4: v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&)) [npm]
 5: 0xb09a37 [npm]
 6: v8::internal::Builtin_HandleApiCall(int, v8::internal::Object**, v8::internal::Isolate*) [npm]
 7: 0xc024b5842fd
Aborted
fivdi commented 7 years ago

Did you read everything at https://github.com/nodejs/node/issues/16649? In particular this comment https://github.com/nodejs/node/issues/16649#issuecomment-340898662 and this comment https://github.com/nodejs/node/issues/16649#issuecomment-340946664? Have you tried with the version of npm bundled with Node 9?

ndaidong commented 7 years ago

@fivdi yes, I've tried with npm bundled with Node 9. I also tried to remove it and reinstall it again with npm u -g npm and got the same result.

fivdi commented 7 years ago

If the bundled version of npm is used it should work. Here's what I see:

$ node -v
v9.0.0
$ npm -v
5.5.1
$ npm install webworker-threads

> webworker-threads@0.7.13 install /home/brian/wwt/node_modules/webworker-threads
> node-gyp rebuild

make: Entering directory `/home/brian/wwt/node_modules/webworker-threads/build'
  CXX(target) Release/obj.target/WebWorkerThreads/src/WebWorkerThreads.o
In file included from ../../nan/nan.h:192:0,
                 from ../src/WebWorkerThreads.cc:12:
../../nan/nan_maybe_43_inl.h: In function ‘Nan::Maybe<bool> Nan::ForceSet(v8::Local<v8::Object>, v8::Local<v8::Value>, v8::Local<v8::Value>, v8::PropertyAttribute)’:
../../nan/nan_maybe_43_inl.h:112:73: warning: ‘v8::Maybe<bool> v8::Object::ForceSet(v8::Local<v8::Context>, v8::Local<v8::Value>, v8::Local<v8::Value>, v8::PropertyAttribute)’ is deprecated (declared at /home/brian/.node-gyp/9.0.0/include/node/v8.h:3114): Use CreateDataProperty / DefineOwnProperty [-Wdeprecated-declarations]
   return obj->ForceSet(isolate->GetCurrentContext(), key, value, attribs);
                                                                         ^
  SOLINK_MODULE(target) Release/obj.target/WebWorkerThreads.node
  COPY Release/WebWorkerThreads.node
make: Leaving directory `/home/brian/wwt/node_modules/webworker-threads/build'
npm WARN saveError ENOENT: no such file or directory, open '/home/brian/wwt/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/home/brian/wwt/package.json'
npm WARN wwt No description
npm WARN wwt No repository field.
npm WARN wwt No README data
npm WARN wwt No license field.

+ webworker-threads@0.7.13
added 3 packages in 9.244s
$ 

Note that the compile warning can be ignored (see https://github.com/nodejs/nan/issues/707 for further details.)

You'll need to figure out why the bundled version of npm is not being used. Note that it's not possible to reinstall the bundled version of npm. So don't do npm u -g npm as this will install the version of npm@5.5.1 that will not work. The bundled version of npm@5.5.1 was patched in order to function correctly.

ndaidong commented 7 years ago

@fivdi I tried to run your commands within a docker container, the error was still occurred:

screenshot_2017-11-01_19-20-36

It looks like the problem does not relate to node-webworker-threads but npm or gcc or something else. I've downgraded Node.js on my computer to v8.9.0 to get things work as before while waiting for the clearer news.