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.