1

I have a Visual Studio project that generates a C++ addon (.node file). When I try to load this node addon in a Node.js application, I get the following error:

{code: 'ERR_DLOPEN_FAILED', stack: 'Error: The specified module could not be found... at
 Object.Module._extensions..node (node:internal/modules/cjs/loader:922:12)', message:
'The specified module could not be found.'}

As we can see in the above error log, there isn't much information on why loading of the node addon failed. I tried using NODE_DEBUG=module and the bindings npm package to see if they provide more information on the load failure, but the info provided by these was no different.

Is there any way to get the reason for the failure of the node addon?

I tried to create a simple node addon in Visual Studio as below, and this simple addon gets loaded without any errors. When I commented out the code in the original project and copy-pasted this simple code, the issue still exists.

#include "pch.h"
#include "node/node.h"
namespace demo {
 void Method(const FunctionCallbackInfo<Value>& args) {
 Isolate* isolate = args.GetIsolate();
 args.GetReturnValue().Set(String::NewFromUtf8(isolate, "hello from node addon").ToLocalChecked());
 }
 void Initialize(Local<Object> exports) {
 NODE_SET_METHOD(exports, "hello", Method);
 }
 NODE_MODULE(addon, Initialize)
}

Maybe there are some project settings leading to the failure which I am unable to figure out. Any help is greatly appreciated.

asked Aug 7, 2024 at 17:45

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.