Skip to content

fix(dev): always use ESM Oxc runtime#21822

Closed
sapphi-red wants to merge 2 commits intovitejs:mainfrom
sapphi-red:fix/always-use-esm-oxc-runtime
Closed

fix(dev): always use ESM Oxc runtime#21822
sapphi-red wants to merge 2 commits intovitejs:mainfrom
sapphi-red:fix/always-use-esm-oxc-runtime

Conversation

@sapphi-red
Copy link
Copy Markdown
Member

ReferenceError: module is not defined error happens in SSR dev for the repro in #21817 because @oxc-project/runtime has node condition before import condition and that node condition points to a CJS file that Vite dev doesn't support.

This PR solves that by resolving to the ESM file regardless of the configuration. This also aligns with the behavior of Rolldown.
While this feels like a workaround, I think it's ok to have this as it aligns the behavior with Rolldown and it might be difficult to change the conditions of @oxc-project/runtime. The conditions probably came from @babel/runtime and it seem they had some back and forth around it (babel/babel#13059 (comment)).

fixes #21817

@sapphi-red sapphi-red added p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority) feat: ssr feat: dev dev server labels Mar 12, 2026
Copy link
Copy Markdown
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know we're overriding deps here, but I suppose it shouldn't cause much issues.

Comment on lines +303 to +305
const runtimePackageDir = getRealPath(
path.join(VITE_PACKAGE_DIR, 'node_modules', '@oxc-project', 'runtime'),
config.resolve.preserveSymlinks,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this will work with yarn pnp (☹️). I think I'd prefer if this is fixed on @oxc-project/runtime side since we have control of it. The exports should just have "import" and "default" without fallback arrays.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yarn pnp... I'll check if we can remove node & require condition and make it ESM only.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with removing node & require condition from @oxc-project/runtime is that @oxc-project/runtime can no longer support older Node versions. This means packages that support older Node versions cannot use Oxc to transform the package and externalize @oxc-project/runtime (so that it can be deduped).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably @oxc-project/runtime can add module-sync and module condition as it doesn't have the problem of babel/babel#12865.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that @oxc-project/runtime has the node engine set as ^20.19.0 || >=22.12.0, so I think it's ok? (if that's what you're referring to). With the package being new, I think (IMO) it can break off some of babel's old decisions.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that range wasn't meant to be there. It doesn't make sense to require a newer version of Node when the job of Oxc is to allow running in older version of Node (and other runtimes) that at least supports ES2015.

graphite-app bot pushed a commit to rolldown/rolldown that referenced this pull request Mar 13, 2026
Expose `oxcRuntimePlugin` as a callable plugin from `rolldown/experimental` to use it in Vite unbundled dev.

The aim is to reduce the inconsistency between dev and build as Rolldown resolves `@oxc-project/runtime` in a special way. The inconsistency caused a bug. See vitejs/vite#21822 for more details.
@sapphi-red
Copy link
Copy Markdown
Member Author

done by #21829

@sapphi-red sapphi-red closed this Mar 19, 2026
@sapphi-red sapphi-red deleted the fix/always-use-esm-oxc-runtime branch March 19, 2026 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: dev dev server feat: ssr p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v8] OXC taggedTemplateEscape is too aggressive

2 participants