Search code examples
node.jsnativev8

v8 NAN support moving from Nodejs 10 to 14


On Windows my NodeJS / Electron app has a dependency on a native library. The app interacts with this library via a 3rd party Node module based on NAN.

This module works well but is out of date. That has forced us to stick with Nodejs v10.x.x. Otherwise the v14.x.x npm install command fails with

error C2661: 'v8::Value::BooleanValue': no overloaded function takes 0 arguments

I was able to track this down to APIs in the v8 engine that were marked depreciated in v10.x.x and removed in v14.x.x (actual v12.x.x). I fixed it locally by changing the code from

info[0]->BooleanValue()

to

info[0]->BooleanValue(Nan::GetCurrentContext()->GetIsolate())

i.e. Similar to this PR on another module.

The downside is that this'll cause errors for people using Node 10.x.x

error C2664: 'bool v8::Value::BooleanValue(void) const': cannot convert argument 1 from 'v8::Isolate *' to 'v8::Local<v8::Context>'

Are there any good approaches to supporting the different versions of Nodejs with a NAN module? i.e. Taking into account the incompatible v8 APIs changes? Can support for the different versions be handled in the code? Or are maintainers forced to release different versions of the module with strict support for Nodejs versions.


Solution

  • Asked the above question on the NodeJS help site and received the following answer

    https://github.com/nodejs/help/issues/2722

    Nan::To<bool>(info[0]).FromJust()

    which worked perfectly for NodeJS 10, 12, and 14.