-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Description
Reproduction
https://github.com/aaronadamsCA/react-router-cloudflare-vite-issue
This is just https://github.com/remix-run/react-router-templates/tree/main/cloudflare with two extra commits.
System Info
System:
OS: Linux 6.8 Ubuntu 24.04.2 LTS 24.04.2 LTS (Noble Numbat)
CPU: (2) x64 Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz
Memory: 3.96 GB / 7.76 GB
Container: Yes
Shell: 5.2.21 - /bin/bash
Binaries:
Node: 22.17.0 - ~/nvm/current/bin/node
Yarn: 1.22.22 - /usr/bin/yarn
npm: 9.8.1 - ~/nvm/current/bin/npm
pnpm: 10.13.1 - ~/nvm/current/bin/pnpm
npmPackages:
@react-router/dev: 7.9.1 => 7.9.1
react-router: 7.9.1 => 7.9.1
vite: 6.3.6 => 6.3.6Used Package Manager
npm
Expected Behavior
If I'm using the latest Cloudflare template, which uses the Vite Environment API, and I import a dependency whose package.json defines multiple exports conditions, the "node" condition should always be skipped.
Actual Behavior
The "node" condition is not skipped.
The repro demonstrates this issue using the "ulid" package. Right now it's being resolved using the wrong condition:
"node_modules/ulid/dist/browser/index.js"- expected ("default"condition)"node_modules/ulid/dist/node/index.js"- actual ("node"condition)
There are two error messages:
12:55:16 PM [vite] Unexpected Node.js imports for environment "ssr". Do you need to enable the "nodejs_compat" compatibility flag? Refer to https://developers.cloudflare.com/workers/runtime-apis/nodejs/ for more details.
- "node:crypto" imported from "node_modules/ulid/dist/node/index.js"
o
12:55:23 PM [vite] Internal server error: Failed to load url node:crypto (resolved id: node:crypto) in /workspaces/react-router-cloudflare-vite-issue/node_modules/.vite/deps_ssr/ulid.js. Does the file exist?
at CustomModuleRunner.cachedModule (runner-worker/index.js:1231:22)
at request (runner-worker/index.js:1152:86)
at null.<anonymous> (/workspaces/react-router-cloudflare-vite-issue/node_modules/ulid/dist/node/index.js:1:1)
at Object.runInlinedModule (runner-worker/index.js:1342:9)
at CustomModuleRunner.directRequest (runner-worker/index.js:1206:61)
at CustomModuleRunner.cachedRequest (runner-worker/index.js:1113:79)
at null.<anonymous> (/workspaces/react-router-cloudflare-vite-issue/app/routes/home.tsx:3:1)
at Object.runInlinedModule (runner-worker/index.js:1342:9)
at CustomModuleRunner.directRequest (runner-worker/index.js:1206:61)
at CustomModuleRunner.cachedRequest (runner-worker/index.js:1113:79)
Enabling "nodejs_compat" might work around the issue, but it definitely shouldn't be necessary, and definitely won't work for every package that defines a "node" condition.
I've only found one way to work around this in the Vite config, and that's to resolve the module specifier myself:
resolve: {
alias: {
ulid: path.resolve("node_modules/ulid/dist/browser/index.js"),
},
},This sounds very similar to this upstream issue: cloudflare/workers-sdk#10260
But I'm still reporting it here because (a) I'm not sure, and (b) it is nevertheless an issue when using the latest Cloudflare template.