Skip to content

Node v20.5.0 issue and fix #43

Closed
Closed
@zack09holland

Description

@zack09holland

I was getting this error originally

Error: Could not locate the bindings file. Tried:
 → /home/user/Documents/workspace/repos/.../.../node_modules/node-postal/build/expand.node
...
...continues on for a bit
...

When on Node v14.18.0, you have to do a node-gyp rebuild within the node-postal module folder, which builds successfully and will recreate the bindings. However when I would do this on Node v20.5.0 it was failing during the make stage

make: *** [expand.target.mk:115: Release/obj.target/expand/src/expand.o] Error 1
make: Leaving directory '/home/user/Documents/workspace/repos/.../.../node_modules/node-postal/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/home/zholland/.nvm/versions/node/v20.5.0/lib/node_modules/node-gyp/lib/build.js:203:23)
gyp ERR! stack     at ChildProcess.emit (node:events:514:28)
gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:294:12)
gyp ERR! System Linux 6.0.6-76060006-generic
gyp ERR! command "/home/user/.nvm/versions/node/v20.5.0/bin/node" "/home/user/.nvm/versions/node/v20.5.0/bin/node-gyp" "rebuild"
gyp ERR! cwd /home/user/Documents/workspace/repos/.../.../node_modules/node-postal
gyp ERR! node -v v20.5.0
gyp ERR! node-gyp -v v9.4.0
gyp ERR! not ok 

Spent a few hours researching both of those issues. I went through the debug logs and saw an error

../src/expand.cc: In function ‘void init(v8::Local<v8::Object>)’:
../src/expand.cc:136:47: error: ‘class v8::Object’ has no member named ‘CreationContext’; did you mean ‘GetCreationContext’?
  136 |     v8::Local<v8::Context> context = exports->CreationContext();
      |                                                                                                  ^~~~~~~~~~~~~~~
      |                                                                                                  GetCreationContext

On an entirely different packages github issues post, someone commented with a change to get the correct JS context and sure enough I was able to run node-gyp rebuild within the node-postal directory to rebind it and the errors went away

Within parser.cc and expand.cc change:
v8::Local<v8::Context> context = exports->CreationContext();

to

v8::Local<v8::Context> context = exports->GetCreationContext().ToLocalChecked();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions