workers-sdk
workers-sdk copied to clipboard
React-Router (Vite Plugin) + Nodejs_compat Crashes on Dev
Which Cloudflare product(s) does this pertain to?
Vite Plugin
What versions & operating system are you using?
Wrangler 4.9.1, Node 22.14.0, Ubuntu 24.04.2 (x86_64)
Please provide a link to a minimal reproduction
https://github.com/cluah/cloudflare-react-router-vite-plugin-node-compat-issue
Describe the Bug
I'm trying to use postgres.js + RR + vite-plugin
To reproduce:
- npx create-react-router@latest --template remix-run/react-router-templates/cloudflare
- set "compatibility_flags": ["nodejs_compat"]
- npm add postgres
- touch app/routes/home.tsx
- npm run dev
// replace app/routes/home.tsx with this:
import postgres from 'postgres';
import type { Route } from './+types/home';
export async function loader() {
const sql = postgres(
'postgresql://react.wjtabypwdxtwbzexsdne:[email protected]:5432/postgres'
);
const res = await sql`select 123;`;
return JSON.stringify(res);
}
export default function Home({ loaderData }: Route.ComponentProps) {
return <div>{loaderData}</div>;
}
Please provide any relevant error logs
node:internal/fs/promises:638
return new FileHandle(await PromisePrototypeThen(
^
Error: ENOENT: no such file or directory, open 'node:events'
at open (node:internal/fs/promises:638:25)
at Object.readFile (node:internal/fs/promises:1242:14)
at extractExportsData (file:///home/cluah/cloudflare-react-router-vite-plugin-node-compat-issue/node_modules/vite/dist/node/chunks/dep-Pj_jxEzN.js:18700:24) {
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: 'node:events'
}
Node.js v22.14.0
Thanks for the issue and reproduction. We are making this a priority and will try to get a fix out asap. I believe this is the same issue referenced here - https://github.com/cloudflare/workers-sdk/issues/8678#issuecomment-2787001800.
Fix released in v1.0.4 of @cloudflare/vite-plugin.