Closed vaaski closed 3 days ago
Thanks I’m keen to try bun and get this working.
From the error it looks like the SQLite dependency isn’t supported.
On Sat, 9 Sep 2023 at 9:55 pm, vaaski @.***> wrote:
Describe the bug After bun https://bun.sh hit v1.0.0 yesterday I was eager to give it a spin, but unfortunately this package doesn't seem to work right out of the box. Not sure what the cause is, but if I find some time I might look into it. error log
bunx pocketbase-typegen --db pb_data/data.db --out plugins/pocketbase-types.ts node:internal/modules/cjs/loader:995 const err = new Error(message); ^
Error: Cannot find module @.***/node_modules/sqlite3/lib/binding/napi-v6-darwin-unknown-arm64/node_sqlite3.node' Require stack:
- @.***/node_modules/sqlite3/lib/sqlite3-binding.js
- @./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.
@./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: [ @./node_modules/sqlite3/lib/sqlite3-binding.js', @./node_modules/sqlite3/lib/sqlite3.js' ] } Node.js v18.12.1 error: "pocketbase-typegen" exited with code 1 (SIGHUP)
Versions pocketbase-typegen version: 1.1.13 pocketbase version: 0.18.1
— Reply to this email directly, view it on GitHub https://github.com/patmood/pocketbase-typegen/issues/79, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA6YGPCS6MCWZLU47L2RDNTXZRN4TANCNFSM6AAAAAA4RNH37U . You are receiving this because you are subscribed to this thread.Message ID: @.***>
Glad to hear you're interested as well! From what I can tell with my little experience with bun, we could probably just use the built-in SQLite driver.
Looks like it might even be possible to use bun test
.
There seems to be one function not implemented, but it already runs crazy fast compared to the jest runner (2s vs 100ms).
Even running each test 100 times is still multiple times faster than jest :D
It was actually rather simple to get running, however I did run into some issues.
Using the build script in your package.json I ran into an issue with ESM. But since bun can run typescript directly, we could theoretically skip that part. I added another bin entry for now.
Bun doesn't like to import directly from the package.json, will be an easy fix tho.
#!/usr/bin/env node
shebang and spin up a node process, which can be disabled using --bun
. We should probably add the shebang during the build process tho.I think ideally there shouldn't be multiple binaries separating the two runtimes, but I'm not sure how to work that into your build setup.
I just tried to reproduce this with bun v1.0.1 and it worked without errors. These all seem like issues that could be fixed on the bun side. Can you try again with the newer version of bun?
I'm also on Mac OSX 12.6.5
It doesn't work for me using bun 1.0.2 on an M2 Mac, OSX v13.5.2
I'm trying to run it as a package.json script
bun run --bun typegen
And it's throwing:
error: Cannot find module "/Users/mattm/Projects/Elucidata/aegis-v4/node_modules/sqlite3/lib/binding/napi-v6-darwin-unknown-arm64/node_sqlite3.node" from "/Users/mattm/Projects/Elucidata/aegis-v4/node_modules/sqlite3/lib/sqlite3-binding.js"
error: script "typegen" exited with code 1 (SIGHUP)
Looks like my issue was Mac Silicon-related. Running this got it to work.
npm install sqlite3 --build-from-source --target_arch=arm64 --fallback-to-build
I'm not sure what the bun version of that command is, though.
I just tried to reproduce this with bun v1.0.1 and it worked without errors. These all seem like issues that could be fixed on the bun side. Can you try again with the newer version of bun?
I'm also on Mac OSX 12.6.5
I just tried it and i could not get it to work. Here's what I did:
bun install pocketbase-typegen
added env variables to my .env
PB_TYPEGEN_URL
PB_TYPEGEN_EMAIL
PB_TYPEGEN_PASSWORD
added the following script to my package.json
"typegen": "pocketbase-typegen --db ./pb_data/data.db"
and ran bunx typegen --env
which yielded 🔍 Resolving... GET https://registry.npmjs.org/typegen/-/typegen-0.2.0.tgz - 404 error: could not determine executable to run for package typegen
I'm on bun 1.0.7 @vaaski did you run into this issue?
@jakubdonovan bunx
is for running packages. So you can run bunx pocketbase-typegen --db ./pb_data/data.db
.
The command for running package.json scripts for your case would be bun run typegen
, since you called the script "typegen"
Whats confusing is that the package entry point does have a node shebang #!/usr/bin/env node
, so it's supposed to be running it with node anyway.
The reason I couldn't repro earlier is because it only errors when trying to generate with the database option.
@jakubdonovan
bunx
is for running packages. So you can runbunx pocketbase-typegen --db ./pb_data/data.db
.The command for running package.json scripts for your case would be
bun run typegen
, since you called the script "typegen"Whats confusing is that the package entry point does have a node shebang
#!/usr/bin/env node
, so it's supposed to be running it with node anyway.The reason I couldn't repro earlier is because it only errors when trying to generate with the database option.
bun run typegen resulted in $ pocketbase-typegen --db ./pb_data/data.db node:internal/process/promises:289 triggerUncaughtException(err, true / fromPromise /); ^
[Error: SQLITE_CANTOPEN: unable to open database file] { errno: 14, code: 'SQLITE_CANTOPEN' }
Node.js v20.3.0 error: script "typegen" exited with code 1 (SIGHUP)
@patmood I was able to get it to work by running
npm i sqlite3 --build-from-source --target_arch=arm64 --fallback-to-build
and
npx pocketbase-typegen --env
which generated types as expected, however I don't think it generated the correct types as
export const pb = new PocketBase(URL) as TypedPocketBase
const res = await pb.collection('menus').getFirstListItem('core_menu_id="628"')
res is of type any and not MenusResponse and each collection in TypedPocketBase gives me the following warning Type 'RecordService' is not generic.ts(2315)
whereas removing as TypedPocketBase
from the client and
const res = await pb.collection(Collections.Menus).getFirstListItem<MenusResponse>('core_menu_id="628"')
gave me the correct type.
This is problematic because I now need to do extra stuff to also get the system fields for say my RecipesRecord.
await pb.collection(Collections.Menus).update(menuRecord.id, {
'collections+': [...collectionRecordIDs]
})
now gives me Property 'id' does not exist on type 'MenusRecord'.ts(2339) because id is a system field. Any suggestions?
Glad to hear you're interested as well! From what I can tell with my little experience with bun, we could probably just use the built-in SQLite driver.
Looks like it might even be possible to use
bun test
. There seems to be one function not implemented, but it already runs crazy fast compared to the jest runner (2s vs 100ms).bun test output Even running each test 100 times is still multiple times faster than jest :D
did you manage to get it to run with the built in sqlite?
bun run typegen
$ pocketbase-typegen --db ./pb_data/data.db node:internal/modules/cjs/loader:1070 const err = new Error(message); ^
Error: Cannot find module '/Users/jakubdonovan/Documents/code/foodDiscounts-datacenter/node_modules/sqlite3/lib/binding/napi-v6-darwin-unknown-arm64/node_sqlite3.node' Require stack:
- /Users/jakubdonovan/Documents/code/foodDiscounts-datacenter/node_modules/sqlite3/lib/sqlite3-binding.js
- /Users/jakubdonovan/Documents/code/foodDiscounts-datacenter/node_modules/sqlite3/lib/sqlite3.js at Module._resolveFilename (node:internal/modules/cjs/loader:1070:15) at Module._load (node:internal/modules/cjs/loader:923:27) at Module.require (node:internal/modules/cjs/loader:1137:19) at require (node:internal/modules/helpers:121:18) at Object.
(/Users/jakubdonovan/Documents/code/foodDiscounts-datacenter/node_modules/sqlite3/lib/sqlite3-binding.js:4:17) at Module._compile (node:internal/modules/cjs/loader:1255:14) at Module._extensions..js (node:internal/modules/cjs/loader:1309:10) at Module.load (node:internal/modules/cjs/loader:1113:32) at Module._load (node:internal/modules/cjs/loader:960:12) at Module.require (node:internal/modules/cjs/loader:1137:19) { code: 'MODULE_NOT_FOUND', requireStack: [ '/Users/jakubdonovan/Documents/code/foodDiscounts-datacenter/node_modules/sqlite3/lib/sqlite3-binding.js', '/Users/jakubdonovan/Documents/code/foodDiscounts-datacenter/node_modules/sqlite3/lib/sqlite3.js' ] } Node.js v20.3.0 error: script "typegen" exited with code 1 (SIGHUP)
bun run --bun typegen
$ pocketbase-typegen --db ./pb_data/data.db error: Cannot find module "/Users/jakubdonovan/Documents/code/foodDiscounts-datacenter/node_modules/sqlite3/lib/binding/napi-v6-darwin-unknown-arm64/node_sqlite3.node" from "/Users/jakubdonovan/Documents/code/foodDiscounts-datacenter/node_modules/sqlite3/lib/sqlite3-binding.js" error: script "typegen" exited with code 1 (SIGHUP) jakubdonovan at …/foodDiscounts-datacenter via db-refactor-relational
@jakubdonovan if you are using as TypedPocketBase
you need to be using PocketBase SDK v0.18.3 or above. If you are using that version, create a new issue with steps to reproduce it.
As mentioned above, bun seems to work after installing the sqlite package for apple silicon. I'm not sure if that is bun related though
bunx --bun pocketbase-typegen -d pb_data/data.db
Created typescript definitions at pocketbase-types.ts
bunx --bun pocketbase-typegen -d pb_data/data.db
That's right, looks like I was on an older version of pocketbase. As for sqlite, how'd you install the apple silicon compatible version?
I saw another user install it with npm install sqlite3 --build-from-source --target_arch=arm64 --fallback-to-build
however using this command with bun instead of npm failed.
I'm using bun v1.1.8 on Windows and runing bun pocketbase-typegen --env -o src/lib/utilities/pb/types-auto-generated.ts
works.
Describe the bug After bun hit v1.0.0 yesterday I was eager to give it a spin, but unfortunately this package doesn't seem to work right out of the box. Not sure what the cause is, but if I find some time I might look into it.
error log
``` bunx pocketbase-typegen --db pb_data/data.db --out plugins/pocketbase-types.ts node:internal/modules/cjs/loader:995 const err = new Error(message); ^ Error: Cannot find module '/private/tmp/pocketbase-typegen@latest--bunx/node_modules/sqlite3/lib/binding/napi-v6-darwin-unknown-arm64/node_sqlite3.node' Require stack: - /private/tmp/pocketbase-typegen@latest--bunx/node_modules/sqlite3/lib/sqlite3-binding.js - /private/tmp/pocketbase-typegen@latest--bunx/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.Versions pocketbase-typegen version: 1.1.13 pocketbase version: 0.18.1
edit probably related to oven-sh/bun#158