fix(dev): always use ESM Oxc runtime#21822
Conversation
bluwy
left a comment
There was a problem hiding this comment.
Didn't know we're overriding deps here, but I suppose it shouldn't cause much issues.
| const runtimePackageDir = getRealPath( | ||
| path.join(VITE_PACKAGE_DIR, 'node_modules', '@oxc-project', 'runtime'), | ||
| config.resolve.preserveSymlinks, |
There was a problem hiding this comment.
I'm not sure if this will work with yarn pnp (@oxc-project/runtime side since we have control of it. The exports should just have "import" and "default" without fallback arrays.
There was a problem hiding this comment.
Oh, yarn pnp... I'll check if we can remove node & require condition and make it ESM only.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Probably @oxc-project/runtime can add module-sync and module condition as it doesn't have the problem of babel/babel#12865.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.
|
done by #21829 |
ReferenceError: module is not definederror happens in SSR dev for the repro in #21817 because@oxc-project/runtimehasnodecondition beforeimportcondition and thatnodecondition 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/runtimeand it seem they had some back and forth around it (babel/babel#13059 (comment)).fixes #21817