oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.27k stars 2.77k forks source link

Cannot find sqlite3/lib/binding/napi-v6-linux-glibc-x64/node_sqlite3.node #4724

Closed einarpersson closed 1 year ago

einarpersson commented 1 year ago

What version of Bun is running?

1.0.0+822a00c4d508b54f650933a73ca5f4a3af9a7983

What platform is your computer?

Linux 5.15.90.1-microsoft-standard-WSL2 x86_64 x86_64

What steps can reproduce the bug?

Run bunx pocketbase-typegen (or bunx --bun pocketbase-typegen)

What is the expected behavior?

I expect that the typegenerator will run and output the same as npx pocketbase-typegen which in case there is no database running will be

Missing schema path. Check options: pocketbase-typegen --help

What do you see instead?

❯ bunx --bun pocketbase-typegen

error: Cannot find module "/home/einar/Projects/local/temp/node_modules/sqlite3/lib/binding/napi-v6-linux-glibc-x64/node_sqlite3.node" from "/home/einar/Projects/local/temp/node_modules/sqlite3/lib/sqlite3-binding.js"
error: "pocketbase-typegen" exited with code 1 (SIGHUP)

or

❯ bunx pocketbase-typegen
node:internal/modules/cjs/loader:995
  const err = new Error(message);
              ^

Error: Cannot find module '/home/einar/Projects/local/temp/node_modules/sqlite3/lib/binding/napi-v6-linux-glibc-x64/node_sqlite3.node'
Require stack:
- /home/einar/Projects/local/temp/node_modules/sqlite3/lib/sqlite3-binding.js
- /home/einar/Projects/local/temp/node_modules/sqlite3/lib/sqlite3.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
    at Module._load (node:internal/modules/cjs/loader:841:27)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/home/einar/Projects/local/temp/node_modules/sqlite3/lib/sqlite3-binding.js:4:17)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/einar/Projects/local/temp/node_modules/sqlite3/lib/sqlite3-binding.js',
    '/home/einar/Projects/local/temp/node_modules/sqlite3/lib/sqlite3.js'
  ]
}

Node.js v18.12.1
error: "pocketbase-typegen" exited with code 1 (SIGHUP)

Additional information

No response

daniellizik commented 1 year ago

same on macos 13.4.1, bun 1.0.0

when i install with npm, the node_sqlite3.node file is present

$ node -v
v18.16.0
$ npm -v
9.5.1
$ npm i sqlite3

Screenshot 2023-09-10 at 8 04 10

installing with bun doesn't download the compiled node addon

$ bun add sqlite3

Screenshot 2023-09-10 at 8 04 25

tanerijun commented 1 year ago

Got the same issue. The workaround is to add the package to trustedDependencies in package.json.

daniellizik commented 1 year ago

@tanerijun hmm if i init a new project with bun and add "sqlite3" to the trusted deps array and then install, it still doesn't fetch the .node addon

$ mkdir test
$ cd test
$ bun init -y
# add "sqlite3" to trustedDependencies
$ bun add sqlite3
$ tree node_modules/sqlite3

node_modules/sqlite3
├── LICENSE
├── README.md
├── binding.gyp
├── deps
│   ├── common-sqlite.gypi
│   ├── extract.js
│   ├── sqlite-autoconf-3410100.tar.gz
│   └── sqlite3.gyp
├── lib
│   ├── sqlite3-binding.js
│   ├── sqlite3.d.ts
│   ├── sqlite3.js
│   └── trace.js
├── package.json
└── src
    ├── async.h
    ├── backup.cc
    ├── backup.h
    ├── database.cc
    ├── database.h
    ├── gcc-preinclude.h
    ├── macros.h
    ├── node_sqlite3.cc
    ├── statement.cc
    ├── statement.h
    └── threading.h
tanerijun commented 1 year ago

I just double checked to be sure, and it's indeed working with trustedDependencies. Here is what I did:

mkdir test-bun
cd test-bun
npm init -y

Edit package.json to look like this:

{
  "name": "test-bun",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "sqlite3": "^5.1.6"
  },
  "trustedDependencies": [
    "sqlite3"
  ]
}

Then install using bun

bun i

Here is the terminal log:

bun add v1.0.0 (822a00c4)

 installed sqlite3@5.1.6

node-pre-gyp info it worked if it ends with ok
node-pre-gyp info using node-pre-gyp@1.0.11
node-pre-gyp info using node@18.16.0 | darwin | arm64
node-pre-gyp info check checked for "/Users/tvince/Projects/test-bun/node_modules/sqlite3/lib/binding/napi-v6-darwin-unknown-arm64/node_sqlite3.node" (not found)
node-pre-gyp http GET https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.6/napi-v6-darwin-unknown-arm64.tar.gz
node-pre-gyp info install unpacking napi-v6-darwin-unknown-arm64/node_sqlite3.node
node-pre-gyp info extracted file count: 1 
[sqlite3] Success: "/Users/tvince/Projects/test-bun/node_modules/sqlite3/lib/binding/napi-v6-darwin-unknown-arm64/node_sqlite3.node" is installed via remote
node-pre-gyp info ok 

 105 packages installed [2.41s]
ineffyble commented 1 year ago

For anyone struggling with getting the postinstall to run for a transitive dependency, delete both node_modules and bun.lockb, make sure the package is in dependencies and trustedDependencies, and then do a bun install.

maximillianus commented 1 year ago

Just wanna share that I have this issue too. My sqlite3 runs fine in my MacOS Venture M1 but when ported to Ubuntu 20.04, it encounters this issue. Thanks @tanerijun and @ineffyble for the tips.

What works for me:


...
1. add trustedDependencies for sqlite3 in package.json
"dependencies": {
  "sqlite3": "^5.1.6"
},
"trustedDependencies": [
  "sqlite3"
]
...
2. Remove node_modules: rm -rf node_modules
3. Fresh install: npm i 
Electroid commented 1 year ago

Duplicate of #4959