Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Module did not self-register #279

Open
Asuza opened this issue Feb 28, 2023 · 9 comments
Open

Error: Module did not self-register #279

Asuza opened this issue Feb 28, 2023 · 9 comments

Comments

@Asuza
Copy link

Asuza commented Feb 28, 2023

Hello! I'm trying to use this library to enable Windows authentication, and it refuses to build for me. After reviewing some of the other issues, I tried using prebuild-install as suggested.

Here are the steps I took.

My Node.js version:

PS C:\Users\me\app\server> fnm current
v18.14.1

Added msnodesqlv8 (edited for brevity):

PS C:\Users\me\app\server> yarn add msnodesqlv8
➤ YN0000: ┌ Resolution step
➤ YN0032: │ msnodesqlv8@npm:3.0.1: Implicit dependencies on node-gyp are discouraged
➤ YN0032: │ nan@npm:2.17.0: Implicit dependencies on node-gyp are discouraged
➤ YN0000: └ Completed in 0s 785ms
➤ YN0000: ┌ Post-resolution validation
➤ YN0000: └ Completed
➤ YN0013: │ msnodesqlv8@npm:3.0.1 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ nan@npm:2.17.0 can't be found in the cache and will be fetched from the remote registry
➤ YN0000: └ Completed in 0s 883ms
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed in 4s 795ms
➤ YN0000: Done with warnings in 6s 830ms

I then ran a version of the following script:

const sql = require('mssql');
const windowsDriver = require('mssql/msnodesqlv8');
const config = {
    driver: windowsDriver,
    server: 'localhost',
    port: 63667,
    database: 'NodeTypeORM',
    options: {
        trustedConnection: true,
        useUTC: true
    }
}
sql.connect(config).then((pool) => {
    console.log('cnnected');
    return pool.request().query('select firstname, lastname from Users').then(res => {
        console.log(res);
    })
}).catch(error=> console.log('cant connect\n'+error));

And the error occurred at this point:

PS C:\Users\me\app\server> node .\connection-test.js
node:internal/modules/cjs/loader:1338
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: Module did not self-register: '\\?\C:\Users\me\app\server\node_modules\msnodesqlv8\build\Release\sqlserverv8.node'.
    at Module._extensions..node (node:internal/modules/cjs/loader:1338:18)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at C:\Users\me\app\server\node_modules\msnodesqlv8\lib\connection.js:10:21
    at Object.<anonymous> (C:\Users\me\app\server\node_modules\msnodesqlv8\lib\connection.js:577:3)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32) {
  code: 'ERR_DLOPEN_FAILED'
}

Node.js v18.14.1

Here is the prebuild-install output, but it looks strange to me compared to tho other issues. Why does it say v1.0.0 all over? Also, the target says 14.17.5. Should it be my Node.js version?

PS C:\Users\me\app\server> yarn run prebuild-install --verbose
prebuild-install info begin Prebuild-install version 7.1.1
prebuild-install info looking for local prebuild @ prebuilds\server-v1.0.0-node-v83-win32-x64.tar.gz
prebuild-install info looking for cached prebuild @ C:\Users\jkrull\AppData\Roaming\npm-cache\_prebuilds\073042-server-v1.0.0-node-v83-win32-x64.tar.gz
prebuild-install http request GET undefined/releases/download/v1.0.0/server-v1.0.0-node-v83-win32-x64.tar.gz
prebuild-install http 400 undefined/releases/download/v1.0.0/server-v1.0.0-node-v83-win32-x64.tar.gz
prebuild-install warn install No prebuilt binaries found (target=14.17.5 runtime=node arch=x64 libc= platform=win32)

I have no idea where to go from here. I even tried installing a few older versions of msnodesqlv8 with no luck. Thanks!

@Asuza
Copy link
Author

Asuza commented Mar 17, 2023

Are there any environment variables that have to be set in order for this package to be installed properly?

@TimelordUK
Copy link
Owner

TimelordUK commented Mar 18, 2023

can we start with the simplest example

if you do following and change connection string in index.,js

then what happens - all binaries for all versions of node for linux,mac and windows are ready built and on release page

js\sql\app
❯ git clone https://github.com/TimelordUK/msnodesqlv8_yarn_sample.git
Cloning into 'msnodesqlv8_yarn_sample'...
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 5 (delta 0), reused 5 (delta 0), pack-reused 0
Receiving objects: 100% (5/5), 6.15 KiB | 3.07 MiB/s, done.

js\sql\app
❯ cd .\msnodesqlv8_yarn_sample\

msnodesqlv8_yarn_sample on  master is 📦 v1.0.0 via  v18.12.0
❯ yarn install
yarn install v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 0.92s.

msnodesqlv8_yarn_sample on  master [?] is 📦 v1.0.0 via  v18.12.0
❯ yarn run test
yarn run v1.22.19
$ node index
using connection 'Driver={ODBC Driver 17 for SQL Server};Server=(localdb)\node;Database=scratch;Trusted_Connection=yes;' run query 'SELECT top 2 * FROM syscolumns'
{
    "elapsed": 2,
    "first": [
        {
            "name": "rsid",
            "id": 3,
            "xtype": 127,
            "typestat": 1,
            "xusertype": 127,
            "length": 8,
            "xprec": 19,
            "xscale": 0,
            "colid": 1,
            "xoffset": 0,
            "bitpos": 0,
            "reserved": 0,
            "colstat": 0,
            "cdefault": 0,
            "domain": 0,
            "number": 0,
            "colorder": 1,
            "autoval": null,
            "offset": 0,
            "collationid": 0,
            "language": 0,
            "status": 0,
            "type": 63,
            "usertype": 0,
            "printfmt": null,
            "prec": 19,
            "scale": 0,
            "iscomputed": 0,
            "isoutparam": 0,
            "isnullable": 0,
            "collation": null,
            "tdscollation": {
                "type": "Buffer",
                "data": [
                    0,
                    0,
                    0,
                    0,
                    0
                ]
            }
        },

this step should automatically happen - the prebuild should as part of install go to release page download the right version and place it in the node_modules/msnodesqlv8/build folder

we can run into issues where for example the project is installed locally running one version of node and it is packaged and installed on a server with different node or even OS - the error you see is Node saying this binary for this project cannot load into this instance of node.

you may now have a corrupted local prebuild cache - so yoiu mag want to delete all related folders as below under Roaming as the prebuild intall will use a local copy if it is there.

❯ .\node_modules\msnodesqlv8\node_modules\.bin\prebuild-install --verbose
prebuild-install info begin Prebuild-install version 7.1.1
prebuild-install info looking for local prebuild @ prebuilds\msnodesqlv8_yarn_sample-v1.0.0-node-v108-win32-x64.tar.gz
prebuild-install info looking for cached prebuild @ C:\Users\me\AppData\Roaming\npm-cache\_prebuilds\238a91-msnodesqlv8-yarn-sample-v1.0.0-node-v108-win32-x64.tar.gz
prebuild-install http request GET undefined/releases/download/v1.0.0/msnodesqlv8_yarn_sample-v1.0.0-node-v108-win32-x64.tar.gz
prebuild-install warn install connect ECONNREFUSED ::1:80

@TimelordUK
Copy link
Owner

the version issue you mention - the above command is just to show you where command is holding cache

what is actually going on during install you can do following#

msnodesqlv8_yarn_sample on  master [?] is 📦 v1.0.0 via  v18.12.0
❯ cd .\node_modules\msnodesqlv8\

msnodesqlv8_yarn_sample\node_modules\msnodesqlv8 on  master [?] is 📦 v3.0.1 via  v18.12.0
❯ yarn run prebuild-install --verbose
yarn run v1.22.19
$ C:\Users\me\dev\js\sql\app\msnodesqlv8_yarn_sample\node_modules\msnodesqlv8\node_modules\.bin\prebuild-install --verbose
prebuild-install info begin Prebuild-install version 7.1.1
prebuild-install info looking for local prebuild @ prebuilds\msnodesqlv8-v3.0.1-node-v108-win32-x64.tar.gz
prebuild-install info looking for cached prebuild @ C:\Users\me\AppData\Roaming\npm-cache\_prebuilds\9e6d0e-msnodesqlv8-v3.0.1-node-v108-win32-x64.tar.gz
prebuild-install info found cached prebuild
prebuild-install info unpacking @ C:\Users\me\AppData\Roaming\npm-cache\_prebuilds\9e6d0e-msnodesqlv8-v3.0.1-node-v108-win32-x64.tar.gz
prebuild-install info unpack resolved to C:\Users\me\dev\js\sql\app\msnodesqlv8_yarn_sample\node_modules\msnodesqlv8\build\Release\sqlserverv8.node
prebuild-install info unpack required C:\Users\me\dev\js\sql\app\msnodesqlv8_yarn_sample\node_modules\msnodesqlv8\build\Release\sqlserverv8.node successfully
prebuild-install info install Successfully installed prebuilt binary!
Done in 0.28s.

msnodesqlv8_yarn_sample\node_modules\msnodesqlv8 on  master [?] is 📦 v3.0.1 via  v18.12.0

@Asuza
Copy link
Author

Asuza commented Mar 21, 2023

I cloned the repo and followed the steps you did above.

PS C:\Users\me\dev> cd .\msnodesqlv8_yarn_sample\
PS C:\Users\me\dev\msnodesqlv8_yarn_sample> yarn install
yarn install v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
[4/4] Building fresh packages...
Done in 33.81s.
PS C:\Users\me\dev\msnodesqlv8_yarn_sample> yarn run test
yarn run v1.22.19
$ node index
node:internal/modules/cjs/loader:1154
                 ^

Error: Module did not self-register: '\\?\C:\Users\me\dev\msnodesqlv8_yarn_sample\node_modules\msnodesqlv8\build\Release\sqlserverv8.node'.
    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1154:18)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:816:12)
    at require (node:internal/modules/cjs/helpers:93:18)
    at C:\Users\me\dev\msnodesqlv8_yarn_sample\node_modules\msnodesqlv8\lib\util.js:5:21
    at Object.<anonymous> (C:\Users\me\dev\msnodesqlv8_yarn_sample\node_modules\msnodesqlv8\lib\util.js:35:3)
    at Module._compile (node:internal/modules/cjs/loader:1095:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)
    at Module.load (node:internal/modules/cjs/loader:975:32) {
  code: 'ERR_DLOPEN_FAILED'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Then did the prebuild-install step after deleting the contents of the _prebuilds folder:

PS C:\Users\me\dev\msnodesqlv8_yarn_sample> .\node_modules\msnodesqlv8\node_modules\.bin\prebuild-install --verbose
prebuild-install info begin Prebuild-install version 7.1.1
prebuild-install info looking for local prebuild @ prebuilds\msnodesqlv8_yarn_sample-v1.0.0-node-v108-win32-x64.tar.gz
prebuild-install info looking for cached prebuild @ C:\Users\me\AppData\Roaming\npm-cache\_prebuilds\238a91-msnodesqlv8-yarn-sample-v1.0.0-node-v108-win32-x64.tar.gz
prebuild-install http request GET undefined/releases/download/v1.0.0/msnodesqlv8_yarn_sample-v1.0.0-node-v108-win32-x64.tar.gz
prebuild-install http 400 undefined/releases/download/v1.0.0/msnodesqlv8_yarn_sample-v1.0.0-node-v108-win32-x64.tar.gz
prebuild-install warn install No prebuilt binaries found (target=18.14.1 runtime=node arch=x64 libc= platform=win32)

So now I'm trying to understand how prebuild-install works so that I can get the undefined part of undefined/releases/download/v1.0.0/msnodesqlv8_yarn_sample-v1.0.0-node-v108-win32-x64.tar.gz to be a URL to your project.

@TimelordUK
Copy link
Owner

you have to cd into the node_modules/msnodesqlv8 folder and run as above it is looking specifically for version based on the package.json file - see above

there is not much in way of dependencies - both kernel32.dll and odbc32.dll which should be on your system fine.

the fact it does not even load is strange - ODBC itself will load the MS driver and it could report a failure to load but then we would get an application error this is saying the module will not even load.

have you tried a different node version out of interest - i have just tried 18.14.1 and it seems to be ok on my platform - i will try some other computers later

node --version
v18.14.1

Administrator in msnodesqlv8_yarn_sample on  master [?] is 📦 v1.0.0 via  v18.14.1
❯ yarn run test
yarn run v1.22.19
$ node index
using connection 'Driver={ODBC Driver 17 for SQL Server};Server=(localdb)\node;Database=scratch;Trusted_Connection=yes;' run query 'SELECT top 2 * FROM syscolumns'
{
"beginAt": "2023-03-22T10:42:26.377Z",
"submittedAt": "2023-03-22T10:42:26.378Z",

dumpbin /dependents sqlserverv8.node
Microsoft (R) COFF/PE Dumper Version 14.35.32215.0
Copyright (C) Microsoft Corporation. All rights reserved.

Dump of file sqlserverv8.node

File Type: DLL

Image has the following dependencies:

KERNEL32.dll
ODBC32.dll

Image has the following delay load dependencies:

node.exe

@TimelordUK
Copy link
Owner

make sure you also have latest MS cpp runtime but that should be on your system if you update on regular basis

the cpp driver is built with the VS2022 toolchain

https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170

should be this one

https://aka.ms/vs/17/release/vc_redist.x64.exe

@Asuza
Copy link
Author

Asuza commented Mar 22, 2023

I install Node.js via fnm because I have to change versions regularly. I wonder if that could be part of the problem, but if so I have to understand why, because that's also used for pipelines and other things. I did try several versions of Node.js before coming here for help.

Here is the last attempt, after correctly changing directories as you pointed out. I had to run yarn install within it, though. I ran all of this after installing vc_redist.x64.exe and rebooting.

PS C:\Users\me\dev\msnodesqlv8_yarn_sample\node_modules\msnodesqlv8> fnm current
v18.14.1

PS C:\Users\me\dev\msnodesqlv8_yarn_sample\node_modules\msnodesqlv8> yarn run prebuild-install --verbose
yarn run v1.22.19
$ C:\Users\me\dev\msnodesqlv8_yarn_sample\node_modules\msnodesqlv8\node_modules\.bin\prebuild-install --verbose
error Couldn't find the binary C:\Users\me\dev\msnodesqlv8_yarn_sample\node_modules\msnodesqlv8\node_modules\.bin\prebuild-install --verbose
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

PS C:\Users\me\dev\msnodesqlv8_yarn_sample\node_modules\msnodesqlv8> yarn install
yarn install v1.22.19
info No lockfile found.
[1/5] Validating package.json...
[2/5] Resolving packages...
warning @types/electron@1.6.10: This is a stub types definition for electron (https://github.com/electron/electron). electron provides its own type definitions, so you don't need @types/electron installed!
warning electron-rebuild@3.2.9: Please use @electron/rebuild moving forward.  There is no API change, just a package name change
warning electron-rebuild > node-gyp > make-fetch-happen > cacache > @npmcli/move-file@2.0.1: This functionality has been moved to @npmcli/fs
warning prebuild > node-ninja > tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
warning prebuild > node-gyp > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning prebuild > node-ninja > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning prebuild > node-gyp > request > uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
warning prebuild > cmake-js > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning prebuild > nw-gyp > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning prebuild > nw-gyp > tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
warning prebuild > node-gyp > request > har-validator@5.1.5: this library is no longer supported
[3/5] Fetching packages...
[4/5] Linking dependencies...
warning " > @typescript-eslint/eslint-plugin-tslint@5.56.0" has unmet peer dependency "tslint@^5.0.0 || ^6.0.0".
warning " > eslint-config-standard-with-typescript@22.0.0" has unmet peer dependency "@typescript-eslint/eslint-plugin@^5.0.0".
warning " > eslint-config-standard-with-typescript@22.0.0" has unmet peer dependency "eslint-plugin-import@^2.25.2".
warning " > eslint-config-standard-with-typescript@22.0.0" has unmet peer dependency "eslint-plugin-n@^15.0.0".
warning " > eslint-config-standard-with-typescript@22.0.0" has unmet peer dependency "eslint-plugin-promise@^6.0.0".
[5/5] Building fresh packages...
[1/4] ⠄ electron
[2/4] ⠄ electron
[3/4] ⠄ lzma-native
error C:\Users\me\dev\msnodesqlv8_yarn_sample\node_modules\msnodesqlv8\node_modules\lzma-native: Command failed.
Exit code: 1
Command: node-gyp-build
Arguments:
Directory: C:\Users\me\dev\msnodesqlv8_yarn_sample\node_modules\msnodesqlv8\node_modules\lzma-native
Output:



PS C:\Users\me\dev\msnodesqlv8_yarn_sample\node_modules\msnodesqlv8>

I'll be researching lzma-native now, and reasons why it might fail.

@gorn
Copy link

gorn commented Sep 18, 2023

Heave you ever find the reason for that? I have somehow similar things happening with electron based app.

@TheThing
Copy link
Contributor

TheThing commented Nov 5, 2023

For reference, I had this problem on both Node 20.9 and Node 21.1 on my windows x64.
However downgrading to Node 18.18.2 worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants