T
TanStack3mo ago
fascinating-indigo

[RC] Cloudflare-vite unable to run dev server and build

I'm unable to run the dev server after upgrading to RC. The issue seems to be related to the getSession in the root's beforeLoad. https://github.com/khashvin/tss-cloudflare/blob/master/src/routes/root.tsx#L16 How can I fix this? Am I missing something? repro: https://github.com/khashvin/tss-cloudflare
✘ [ERROR] Could not resolve "sqlite"

node_modules/.pnpm/wrangler@4.40.2/node_modules/wrangler/wrangler-dist/cli.js:17007:33:
17007 │ DatabaseSync = require("sqlite").DatabaseSync;
╵ ~~~~~~~~

You can mark the path "sqlite" as external to exclude it from the bundle, which will remove this
error and leave the unresolved path in the bundle. You can also surround this "require" call with
a try/catch block to handle this failure at run-time instead of bundle-time.

✘ [ERROR] Could not resolve "./node.js"

node_modules/.pnpm/blake3-wasm@2.1.5/node_modules/blake3-wasm/esm/index.js:13:14:
13 │ export * from './node.js';
╵ ~~~~~~~~~~~

7:47:21 PM [vite] (ssr) warning: Automatically externalized node built-in module "node:sqlite" imported from "node_modules/.pnpm/undici@7.14.0/node_modules/undici/lib/cache/sqlite-cache-store.js". Consider adding it to environments.ssr.external if it is intended.
Plugin: vite:resolve
✘ [ERROR] Cannot read file: /home/khk/workspaces/tss-cloudflare/node:sqlite

node_modules/.pnpm/undici@7.14.0/node_modules/undici/lib/cache/sqlite-cache-store.js:113:29:
113 │ DatabaseSync = require('node:sqlite').DatabaseSync
╵ ~~~~~~~~~~~~~

7:47:21 PM [vite] (ssr) error while updating dependencies:
Error: Error during dependency optimization:

✘ [ERROR] Could not resolve "./node.js"

node_modules/.pnpm/blake3-wasm@2.1.5/node_modules/blake3-wasm/esm/index.js:13:14:
13 │ export * from './node.js';
╵ ~~~~~~~~~~~
✘ [ERROR] Could not resolve "sqlite"

node_modules/.pnpm/wrangler@4.40.2/node_modules/wrangler/wrangler-dist/cli.js:17007:33:
17007 │ DatabaseSync = require("sqlite").DatabaseSync;
╵ ~~~~~~~~

You can mark the path "sqlite" as external to exclude it from the bundle, which will remove this
error and leave the unresolved path in the bundle. You can also surround this "require" call with
a try/catch block to handle this failure at run-time instead of bundle-time.

✘ [ERROR] Could not resolve "./node.js"

node_modules/.pnpm/blake3-wasm@2.1.5/node_modules/blake3-wasm/esm/index.js:13:14:
13 │ export * from './node.js';
╵ ~~~~~~~~~~~

7:47:21 PM [vite] (ssr) warning: Automatically externalized node built-in module "node:sqlite" imported from "node_modules/.pnpm/undici@7.14.0/node_modules/undici/lib/cache/sqlite-cache-store.js". Consider adding it to environments.ssr.external if it is intended.
Plugin: vite:resolve
✘ [ERROR] Cannot read file: /home/khk/workspaces/tss-cloudflare/node:sqlite

node_modules/.pnpm/undici@7.14.0/node_modules/undici/lib/cache/sqlite-cache-store.js:113:29:
113 │ DatabaseSync = require('node:sqlite').DatabaseSync
╵ ~~~~~~~~~~~~~

7:47:21 PM [vite] (ssr) error while updating dependencies:
Error: Error during dependency optimization:

✘ [ERROR] Could not resolve "./node.js"

node_modules/.pnpm/blake3-wasm@2.1.5/node_modules/blake3-wasm/esm/index.js:13:14:
13 │ export * from './node.js';
╵ ~~~~~~~~~~~
5 Replies
graceful-beige
graceful-beige3mo ago
you have to install better-sqlite3cause locally, its use a sqlite file
fascinating-indigo
fascinating-indigoOP3mo ago
same issue after installing it. it was working before this with D1 locally before I upgraded to RC
graceful-beige
graceful-beige3mo ago
get rid of bindings.ts get env like this `import { env } from 'cloudflare:workers';``
fascinating-indigo
fascinating-indigoOP3mo ago
yep that was the issue. Thanks! @stunaz
conscious-sapphire
conscious-sapphire4w ago
This worked for me too! To clarify, I needed to completely delete my old code which was loading the bindings since it was doing it at the module level, i.e. triggering the bad code when running dev or deploy even though it wasn't in use anymore. import { env } from 'cloudflare:workers'; Wish I had known about this sooner

Did you find this page helpful?