nodejs / help

:sparkles: Need help with Node.js? File an Issue here. :rocket:
1.44k stars 276 forks source link

sqlite3 5.1.7 will not require or import on nodejs #4412

Closed woodbri closed 2 weeks ago

woodbri commented 4 weeks ago

Node.js Version

v21.7.2

NPM Version

10.5.0

Operating System

MINGW64_NT-10.0-19045 DESKTOP-MD7Q6H6 3.5.3.x86_64 2024-05-06 06:45 UTC x86_64 Msys

Subsystem

Other

Description

I can not get sqlite3 5.1.7 to import or require into a script. It throws a kill. I have tried multiple way of doing this with no success.

Minimal Reproduction

$ cat package.json
{
  "name": "test-sqlite3",
  "version": "0.1.0",
  "private": true,
  "scripts": {
  },
  "dependencies": {
    "sqlite3": "^5.1.7"
  }
}
$ cat test4
#!/usr/bin/env node

const sqlite3 = require( 'sqlite3' );

console.log('Connecting to DB');

sqlite3.verbose();
let db = new sqlite3.Database(':memory:', (err) => {
        if (err) {
                return console.error(err.message);
        }

        console.log('Connected to DB.');
});

console.log('Closing DB');

db.close((err) => {
        if (err) {
                return console.error(err.message);
        }
});

console.log('DB closed, Exiting');

Alternatively using "type": "module" in package.json

$ cat test2
#!/usr/bin/env node

import sqlite3 from 'sqlite3';

console.log('Connecting to DB');

sqlite3.verbose();
let db = new sqlite3.Database(':memory:', (err) => {
        if (err) {
                return console.error(err.message);
        }

        console.log('Connected to DB.');
});

console.log('Closing DB');

db.close((err) => {
        if (err) {
                return console.error(err.message);
        }
});

console.log('DB closed, Exiting');

Output

$ node inspect test2
< Debugger listening on ws://127.0.0.1:9229/6ac6169c-e11b-4540-834f-4424cb5ad943
< For help, see: https://nodejs.org/en/docs/inspector
<
connecting to 127.0.0.1:9229 ... ok
Break on start in test2:1
> 1 #!/usr/bin/env node
  2
  3 import sqlite3 from 'sqlite3';
debug> n
debug> There was an internal error in Node.js. Please report this bug.
read ECONNRESET
Error: read ECONNRESET
    at TCP.onStreamRead (node:internal/stream_base_commons:217:20)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17)
node:events:497
      throw er; // Unhandled 'error' event
      ^

Error: kill EPERM
    at ChildProcess.kill (node:internal/child_process:512:26)
    at process.handleUnexpectedError (node:internal/debugger/inspect:360:42)
    at process.emit (node:events:531:35)
    at process.emit (node:domain:488:12)
    at process._fatalException (node:internal/process/execution:178:25)
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess.kill (node:internal/child_process:512:12)
    at process.handleUnexpectedError (node:internal/debugger/inspect:360:42)
    [... lines matching original stack trace ...]
    at process._fatalException (node:internal/process/execution:178:25) {
  errno: -4048,
  code: 'EPERM',
  syscall: 'kill'
}

Node.js v21.7.2

Before You Submit

RedYetiDev commented 4 weeks ago

Two notes:

  1. Please reformat your question to use proper styling
  2. This is an issue with what seems to be a third-party package, have you tried reaching out to them?
woodbri commented 4 weeks ago

I've simplified the test case to:

npm install sqlite@5.1.7
node -e 'require("sqlite3")'
node:internal/modules/cjs/loader:1464
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: A dynamic link library (DLL) initialization routine failed.
\\?\C:\msys64\home\woodbri\work\test-sqlite3\node_modules\sqlite3\lib\binding\napi-v6-win32-unknown-
x64\node_sqlite3.node
    at Module._extensions..node (node:internal/modules/cjs/loader:1464:18)
    at Module.load (node:internal/modules/cjs/loader:1205:32)
    at Module._load (node:internal/modules/cjs/loader:1021:12)
    at Module.require (node:internal/modules/cjs/loader:1230:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (C:\msys64\home\woodbri\work\test-sqlite3\node_modules\sqlite3\lib\sqlite3
-binding.js:4:17)
    at Module._compile (node:internal/modules/cjs/loader:1368:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)
    at Module.load (node:internal/modules/cjs/loader:1205:32)
    at Module._load (node:internal/modules/cjs/loader:1021:12) {
  code: 'ERR_DLOPEN_FAILED'
}

Node.js v21.7.2

I've also tried this with sqlite3 versions 5.1.5, 5.1.6, and 5.1.7 and get the same results. Yes looked at the package site and see various similar problems and tried various work-a-rounds.

This is such a simple test and I find it hard to believe that no one can run sqlite3 in nodejs in msys2/mingw64 environment.

woodbri commented 4 weeks ago

Same issue using --import=sqlite3

$ node --import=sqlite3
node:internal/modules/cjs/loader:1464
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: A dynamic link library (DLL) initialization routine failed.
\\?\C:\msys64\home\woodbri\work\test-sqlite3\node_modules\sqlite3\lib\binding\napi-v6-win32-unknown-
x64\node_sqlite3.node
    at Module._extensions..node (node:internal/modules/cjs/loader:1464:18)
    at Module.load (node:internal/modules/cjs/loader:1205:32)
    at Module._load (node:internal/modules/cjs/loader:1021:12)
    at Module.require (node:internal/modules/cjs/loader:1230:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (C:\msys64\home\woodbri\work\test-sqlite3\node_modules\sqlite3\lib\sqlite3
-binding.js:4:17)
    at Module._compile (node:internal/modules/cjs/loader:1368:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)
    at Module.load (node:internal/modules/cjs/loader:1205:32)
    at Module._load (node:internal/modules/cjs/loader:1021:12) {
  code: 'ERR_DLOPEN_FAILED'
}

Node.js v21.7.2
woodbri commented 4 weeks ago

https://github.com/TryGhost/node-sqlite3/issues/1792

woodbri commented 3 weeks ago

I installed sqlite3 with

pacman -S mingw-w64-x86_64-sqlite3

and this seems to get rid is DLL loading error but is now goes back to the original error

$ node inspect -e 'require("sqlite3")'
< Debugger listening on ws://127.0.0.1:9229/45ec13d8-2c3d-445c-8f04-d7370eefbd82
< For help, see: https://nodejs.org/en/docs/inspector
<
connecting to 127.0.0.1:9229 ... ok
Break on start in [eval]:1
> 1 require("sqlite3")
debug> n
debug> There was an internal error in Node.js. Please report this bug.
read ECONNRESET
Error: read ECONNRESET
    at TCP.onStreamRead (node:internal/stream_base_commons:217:20)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17)
node:events:497
      throw er; // Unhandled 'error' event
      ^

Error: kill EPERM
    at ChildProcess.kill (node:internal/child_process:512:26)
    at process.handleUnexpectedError (node:internal/debugger/inspect:360:42)
    at process.emit (node:events:531:35)
    at process.emit (node:domain:488:12)
    at process._fatalException (node:internal/process/execution:178:25)
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess.kill (node:internal/child_process:512:12)
    at process.handleUnexpectedError (node:internal/debugger/inspect:360:42)
    [... lines matching original stack trace ...]
    at process._fatalException (node:internal/process/execution:178:25) {
  errno: -4048,
  code: 'EPERM',
  syscall: 'kill'
}

Node.js v21.7.2

SO, this is clearly not a programming issue. It appears to be an issue between nodejs and sqlite3. I've reported this on both sites but am totally stuck in the water!

RedYetiDev commented 2 weeks ago

This appears to be an issue with a specific package. Please report to them and obtain more information about whether this is actually a problem with node before reporting an issue

Thank you