'Could not find module route...'

#9 · closed · 3 comments

View on GitHub ↗

revslaughter

Hi there! I'm excited to try this out. I'm trying to compile an offline kiosk app that uses a local sqlite3 database, and I'm trying this out - I'm pretty excited about the project! It'll help my client not have intermediate steps in the testing process. My svelte config is: ```js import adapter from '@jesterkit/exe-sveltekit'; import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; /** @type {import('@sveltejs/kit').Config} */ const config = { preprocess: vitePreprocess(), kit: { adapter: adapter({ binaryName: 'xoMealTrak', target: 'macos-arm64', volume: '/db' }) } }; export default config; ``` Though I'll ultimately be targeting windows, I'm just trying this out on my machine (M1 Pro MacBook / arm64) first. I compile without issue, but running the resulting binary gives me: ``` 791 | dir = process.cwd(); 792 | } 793 | if (exists(join(dir, "package.json")) || exists(join(dir, "node_modules"))) { 794 | return dir; 795 | } 796 | throw new Error('Could not find module root given file: "' + file + '". Do you have a `package.json` file? '); ^ error: Could not find module root given file: "/$bunfs/root/xoMealTrak". Do you have a `package.json` file? at getRoot (/$bunfs/root/xoMealTrak:796:15) at bindings (/$bunfs/root/xoMealTrak:726:41) at new Database (/$bunfs/root/xoMealTrak:1334:67) at <anonymous> (/$bunfs/root/xoMealTrak:5453:12) at <anonymous> (/$bunfs/root/xoMealTrak:28:48) at <anonymous> (/$bunfs/root/xoMealTrak:9736:14) at <anonymous> (/$bunfs/root/xoMealTrak:28:48) at <anonymous> (/$bunfs/root/xoMealTrak:11166:111) Bun v1.3.0 (macOS arm64) Saving session...completed. [Process completed] ``` and the process doesn't run. I've freshly installed Bun - I'd expect this _not_ to need a package.json file if I'm distributing it, right? Am I making some mistake in configuration? At my project root, my database is in my `/db` folder. Thanks! This is really promising, I can't wait to get it to work.

Comments

revslaughter

Oh! And it looks like the `new Database` call is indeed asking for the local database file, the source for this is probably my `connect.server.ts` file: ```ts import Database from 'better-sqlite3'; import { drizzle } from 'drizzle-orm/better-sqlite3'; const url = 'db/mealtrak.db'; const client = new Database(url); const db = drizzle(client); export default db; ```

Hugo-Dz

Hey @revslaughter , thanks posting this! I think it's because `better-sqlite3` relies on native Node modules. Which requires it to find a `node_modules` and a `package.json` at runtime to work. Could you try with the [Bun SQlite](https://bun.com/docs/api/sqlite) ?

revslaughter

Thank you! I'm at least getting a more normal 'cant find the database file' error, but the driver is now loading. Thanks for the suggestion!