agracio / edge-js

Run .NET and Node.js code in-process on Windows, macOS, and Linux
MIT License
643 stars 95 forks source link

Module did not self-register for edge_nativeclr.node | code: 'ERR_DLOPEN_FAILED' with Node 18 #163

Closed kakkar17 closed 2 years ago

kakkar17 commented 2 years ago

Issue: Module did not self-register for edge_nativeclr.node | code: 'ERR_DLOPEN_FAILED' with Node 18

Error:

Error: Module did not self-register: '\\?\C:\projects\edge-js\lib\native\win32\x64\18.4.0\edge_nativeclr.node'.
    at Module._extensions..node (node:internal/modules/cjs/loader:1203:18)
    at Module.load (node:internal/modules/cjs/loader:997:32)
    at Module._load (node:internal/modules/cjs/loader:838:12)
    at Module.require (node:internal/modules/cjs/loader:1021:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (C:\projects\edge-js\lib\edge.js:52:8)
    at Module._compile (node:internal/modules/cjs/loader:1119:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1173:10)
    at Module.load (node:internal/modules/cjs/loader:997:32)
    at Module._load (node:internal/modules/cjs/loader:838:12) {
  code: 'ERR_DLOPEN_FAILED'
}

The same error is happening here for Node 18 in this CI run: https://ci.appveyor.com/project/agracio/edge-js/builds/44772581/job/uyvrmskvw2tac57a

If anyone is facing this error, please find the below resolution.

Resolution: This needed to build your own binaries for your specific node version. In this below case, I tested out with Node 18.9.0

Step 1: Upgrade nan to latest 2.16.0 (https://www.npmjs.com/package/nan) ref: https://github.com/agracio/edge-js/blob/c1cfba1f063cf9c8fb983809eb08d114719cc6dc/package.json#L40

Step 2: Change this NODE_MODULE initialization to NAN_MODULE_WORKER_ENABLED ref: https://github.com/agracio/edge-js/blob/c1cfba1f063cf9c8fb983809eb08d114719cc6dc/src/common/edge.cpp#L84-L86

-->

        #if NODE_MAJOR_VERSION >= 10
        NAN_MODULE_WORKER_ENABLED(edge_coreclr, init)
    #else
        NODE_MODULE(edge_coreclr, init)
    #endif
#else
    #if NODE_MAJOR_VERSION >= 10
        NAN_MODULE_WORKER_ENABLED(edge_nativeclr, init)
    #else
        NODE_MODULE(edge_nativeclr, init)
    #endif

or

NAN_MODULE_WORKER_ENABLED(edge_coreclr, init)
#else
NAN_MODULE_WORKER_ENABLED(edge_nativeclr, init)

Step 3: Change this to your targeted node version. In my case, it's 18.9.0 https://github.com/agracio/edge-js/blob/c1cfba1f063cf9c8fb983809eb08d114719cc6dc/lib/edge.js#L9

Step 4: Build it with the targeted node version (ex: 18.9.0)

The new edge_nativeclr.node will not have the above issue and works fine with the node 18.9.0

@agracio - Can you please build this above for node 18.9.0? So that, we do not have to create/build separate binaries for this issue. Thanks in the advance!

agracio commented 2 years ago

Updated and published to npm.