Skip to content

Failure to install on modern versions of Node.js (node-gyp compilation error from deprecated GetContents() function) #2

@trinitronx

Description

@trinitronx

Related to the issue with pinning nan 2.4.0, this project fails to build on newer versions of Node.js.

The main compile error from node-gyp is related to GetContents() being deprecated in Node.js 14.

Expand for full compile log:

../qrusage.cc: In function ‘double* getFloat64ArrayPointer(unsigned int, v8::Local<v8::Value>)’:
../qrusage.cc:25:55: error: ‘class v8::ArrayBuffer’ has no member named ‘GetContents’
   25 |             double* fields = static_cast<double*>(ab->GetContents().Data());
      |                                                       ^~~~~~~~~~~

The fix can be seen in nan 2.4.1, which adds a C pre-processor directive checking for (V8_MAJOR_VERSION >= 8). If nodejs built-in V8 headers define this to be 8 or greater, then they use the new GetBackingStore() function. Otherwise, they fall back on using GetContents().

// Actually it's 7.9 here but this would lead to ABI issues with Node.js 13
// using 7.8 till 13.2.0.
#if (V8_MAJOR_VERSION >= 8)
      data = static_cast<char*>(buffer->GetBackingStore()->Data()) + byte_offset;
#else
      data = static_cast<char*>(buffer->GetContents().Data()) + byte_offset;
#endif

The V8_MAJOR_VERSION definition can be found in v8-version.h from Node.js installation. Usually this is in /usr/include/node/v8-version.h.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions