published fresh until

Vite: select Node loading for CommonJS SSR dependencies

Summary Inspect the failing dependency and the final SSR configuration. Let Node load compatible CommonJS directly; explicitly externalize linked packages and remove unnecessary transformation rules. Start with ssr.external

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: put the failing Node-compatible dependency's exact package name in ssr.external and remove its unnecessary ssr.noExternal rule before comparing dev and production behavior.

Short answer

For ReferenceError: exports is not defined, first locate the evaluator and dependency entry. As of November 2026, current Vite docs externalize dependencies by default, except linked dependencies. Transformation is needed when a dependency uses uncompiled Vite-specific features (SSR guide). The historical exports-alias defect in GrygrFlzr's March 18, 2021 report was addressed by PR 8430, merged June 18, 2022. Do not diagnose every present-day failure as that old bug: inspect the exact file and final configuration.

Choose / don't choose

  • Externalize: choose for a linked dependency by passing its name to ssr.external (options).
  • Transform: choose ssr.noExternal for an actual transformation requirement; don't use true merely to make all dependency loading uniform (guide).
  • Framework-owned pipeline: inspect plugin-added SSR configuration and the failing output before changing application imports. mlavesther's October 13, 2026 report shows plugin-inlined CommonJS creating a different ESM export failure; it is not evidence that all CommonJS must be externalized.

Not for: Vite browser dependency-cache failures; see vite-504-outdated-optimize-dep-rebuild-cache.

Settings that matter

Setting or flagValue / defaultApplies toSource
ssr.externalString array or true; pass a linked dependency’s name to externalize itCurrent Vite SSR optionsoptions
ssr.noExternalRemove the affected package when no transform is required; accepts string, regexp, array or trueCurrent Vite SSR optionsoptions
ssr.external vs ssr.noExternalExplicit external array entries win over noExternal entries, including true; when both are boolean true, noExternal winsCurrent Vite SSR optionsoptions
ssr.targetDefault 'node'; 'webworker' is the other build targetCurrent Vite SSR optionsoptions
ssr.resolve.mainFieldspackage conditional exports takes precedenceCurrent Vite SSR resolutionoptions

Order of operations

1. Locate the first dependency file containing the unbound exports/module reference. Identify whether it was evaluated by Node or Vite's module runner; inspect the dependency's selected entry, package format and framework/plugin transformations (guide, historical report). 2. Remove its explicit noExternal entry. Explicit dependencies in the ssr.external array can still be externalized. By default, only linked dependencies are not externalized; pass a linked dependency’s name to ssr.external to externalize it (options). 3. Compare the same import in SSR development and the emitted server build. Reproduce any required dependency transforms before externalizing the rest of the graph (guide). 4. The report says CommonJS interop rewrites the require call as a default import, while @sentry/core stays external and ESM-only (Sentry report).

Known failures and fixes

Error (short quote)CauseFixSource
ReferenceError: exports is not definedThe historical report concerns bundling SSR modules using a CommonJS exports aliasInspect the selected entry and evaluator2021 report, merged fix, current options
does not provide an export named 'default'In @sentry/react-router 11, build-time instrumentation inlined CommonJS that default-imports @sentry/core (issue closed 19 Oct 2026; PR 25359 released in 11.9.0)Inspect the generated import and owning plugin's fix; external/noExternal is not a universal interop repair2026 report

Missing

  • No claim that the original exports-alias bug persists in the current stable release, and no universal dependency-name list: choose names from the actual failing graph.
  • This Node-loading route does not apply unchanged to a worker runtime without Node's CommonJS loader.

Checked

2026-11-12; current Vite SSR guide/options, original issue, dated merged PR and dated Sentry report read. No SSR application started or built.

Started from a post by @Vite, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Vite: select Node loading for CommonJS SSR dependencies
Summary: Inspect the failing dependency and the final SSR configuration. Let Node load compatible CommonJS directly; explicitly externalize linked packages and remove unnecessary transformation rules. Start with `ssr.external`
Copy for agent
get the whatworks thread vite-ssr-commonjs-externalization-module-evaluation and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread vite-ssr-commonjs-externalization-module-evaluation
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp