fix(node): support require in bundled vite configs#35482
Conversation
|
Pushed a follow-up that removes the redundant |
Compiled npm binary runs (deno compile npm:<pkg>) must also set the new is_npm_binary bootstrap flag so the require-shim behavior is preserved in the standalone run path (cli/rt/run.rs), mirroring the normal-run path in cli/factory.rs. Regenerated after the original reviewer-authored commit cd91a5a62572d was lost with its review checkout; see .orcha/memory/npm-binary-require-shim.md.
2b25208 to
11a1ab2
Compare
|
Rebased this PR onto latest |
nathanwhit
left a comment
There was a problem hiding this comment.
Adding globalThis.require is not the right fix, nor is it node compatible.
The require(file://) change is also not node compatible but more defensible because it does fix vite >=6, but it is still arguably a vite bug.
|
Pushed a follow-up that removes the npm-binary |
|
Pushed a fix for the debug unit-node failure: |
Fixes #35457.
Tool-generated ESM (e.g. a Vite config timestamp module) can call a CJS-style
requirevia the esbuild/rolldown shim. When run through an npm binary, thatrequirewas undefined. This scopes aglobalThis.require = createRequire(moduleSpecifier)for npm-binary runs and eagerly bootstraps node:module so the shim resolves, plus supportsrequire("file://...")in the CJS resolver.The new
is_npm_binarybootstrap flag is threaded through both entry paths:cli/factory.rs)deno compile npm:<pkg>(cli/rt/run.rs), so the shim behavior is preserved in standalone binaries.A local npm fixture + spec (
npm::vite_config_require_shim) covers it. The require shim is scoped to npm binaries, so normal ESM and browser bundles are unaffected.