fix(vite): do not force node condition in non-Node environments#14936
fix(vite): do not force node condition in non-Node environments#14936Kanevry wants to merge 2 commits intoremix-run:devfrom
Conversation
…x-run#14730) When v8_viteEnvironmentApi is enabled, the node resolve condition was unconditionally added to externalConditions for all SSR environments via getBaseServerOptions(). This caused builds to break for non-Node runtimes like Cloudflare Workers, which cannot import Node builtins. The fix: 1. getBaseServerOptions(): when v8_viteEnvironmentApi is enabled, externalConditions no longer includes node. 2. configEnvironment hook: node is only added to externalConditions when options.resolve?.noExternal !== true. The noExternal signal is already used by @cloudflare/vite-plugin. Node.js environments are unaffected (noExternal is not set). Legacy mode (v8_viteEnvironmentApi=false) is also unaffected. Fixes remix-run#14730
|
Hi @Kanevry, Welcome, and thank you for contributing to React Router! Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once. You may review the CLA and sign it by adding your name to contributors.yml. Once the CLA is signed, the If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at [email protected]. Thanks! - The Remix team |
🦋 Changeset detectedLatest commit: ac1029e The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳 |
What
Stop unconditionally adding the
"node"condition toexternalConditionsfor all SSR environments whenv8_viteEnvironmentApiis enabled. Instead, set it per-environment in theconfigEnvironmenthook so that non-Node runtimes are not forced to resolve Node.js-specific package exports.Fixes #14730
Why
The Vite plugin hardcodes
let defaultExternalConditions = ["node"]ingetBaseServerOptions()and applies it to all SSR environments. When deploying to Cloudflare Workers (or other edge runtimes), this forces Vite to resolve Node.js-specific exports from packages, causing builds to fail because these runtimes cannot import builtins likehttpandhttps.The
"node"condition was deliberately introduced in #13871 because Vite does not exportdefaultExternalConditions. However, it should not be applied to non-Node environments.How
Two changes in
packages/react-router-dev/vite/plugin.ts:getBaseServerOptions(): Whenv8_viteEnvironmentApiis enabled,externalConditionsno longer includes"node". This mirrors howresolve.externalis already conditional onv8_viteEnvironmentApi.configEnvironmenthook:"node"is added toexternalConditionsonly whenoptions.resolve?.noExternal !== true. This uses the samenoExternalsignal already checked in this hook forresolve.external, set by@cloudflare/vite-pluginfor non-Node runtimes.Behavior by scenario:
v8_viteEnvironmentApi=true):"node"added viaconfigEnvironment— same as beforev8_viteEnvironmentApi=true,noExternal: true):"node"NOT added — fixv8_viteEnvironmentApi=false): unchangedTest Plan
pnpm build— all packages build successfullypnpm typecheck— zero type errorspnpm lint— zero new errors