workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

React-Router (Vite Plugin) + Nodejs_compat Crashes on Dev

Open cluah opened this issue 1 year ago • 2 comments

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:

  1. npx create-react-router@latest --template remix-run/react-router-templates/cloudflare
  2. set "compatibility_flags": ["nodejs_compat"]
  3. npm add postgres
  4. touch app/routes/home.tsx
  5. 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

cluah avatar Apr 08 '25 22:04 cluah

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.

jamesopstad avatar Apr 09 '25 08:04 jamesopstad

Fix released in v1.0.4 of @cloudflare/vite-plugin.

jamesopstad avatar Apr 09 '25 14:04 jamesopstad