Repository navigation
Conversation
🦋 Changeset detectedLatest commit: 9c44bf8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
This comment was marked as resolved.
This comment was marked as resolved.
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
There was a problem hiding this comment.
🟢 Approval recommended
The focused resolver fix preserves the legacy hint, includes regression coverage, and has no unresolved findings.
No open issues 🎉
What changed in this PR
Fixes CommonJS dependencies resolving to ESM exports on supported Vite 8 releases in the Workers Vitest integration.
Changes:
- Passes import kind through Vite’s SSR environment resolver while preserving the legacy resolution hint.
- Adds regression coverage and updates resolver stubs.
- Adds a patch changeset.
| File | Description |
|---|---|
| packages/vitest-plugin/test/module-fallback.test.ts | Updates stubs to use the SSR environment container. |
| packages/vitest-plugin/test/cjs-require.test.ts | Tests CommonJS resolution of dual-format packages. |
| packages/vitest-plugin/src/pool/module-fallback.ts | Passes the require/import kind to Vite. |
| .changeset/vitest-plugin-require-condition.md | Documents the resolution fix for release. |
Review effort: Balanced
|
OK let's re-open this and consider if it is the correct fix. |
|
This pull request was not reviewed automatically because its author does not have write access to this repository. A maintainer with write access can start a review by commenting |
@cloudflare/autoconfig
@cloudflare/build-output-utils
@cloudflare/codemods
@cloudflare/config
@cloudflare/containers-shared
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-functions
@cloudflare/pages-shared
@cloudflare/runtime-types
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-plugin
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
|
clanker review |
67802f2 to
9ad304d
Compare
|
Codeowners approval required for this PR:
Show detailed file reviewers |
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
57d7ddb to
5e72806
Compare
petebacondarwin
left a comment
There was a problem hiding this comment.
OK this LGTM.
Are we saying that this fix doesn't work on Vite 8.0.x, 8.1.x, and 8.2.0?
If so, I think we should mention that in the changeset.
workers-devprod
left a comment
There was a problem hiding this comment.
Codeowners reviews satisfied
|
Yes. The fix needs rolldown 1.2.1 or later (rolldown/rolldown#10440), and Vite 8.2.1 is the first release that ships it. Vite 8.0.x, 8.1.x and 8.2.0 stay affected. I added that to the changeset and applied your suggestion. |
Fixes #12984.
Fixes #13037.
On Vite 8, a
require()in a CommonJS dependency resolved to theimportentry of packages that ship both animportand arequireentry. CommonJS code then got an ES module. Withpg, for example, tests fail withSyntaxError: Cannot use import statement outside a module.Why
viteResolve()in the module fallback service told Vite about arequire()only throughcustom: { "node-resolve": { isRequire } }. Vite 7's resolve plugin reads that hint. Vite 8 uses rolldown's nativeviteResolvePlugininstead, and nothing reads the hint anymore. The native plugin picksrequireorimportfrom thekindof each call. We passed nokind, so every lookup counted as an import.Before rolldown 1.2.1, a
kindpassed from JS never reached the native plugin (rolldown/rolldown#10403). That is why #13062 had to rescan theexportsmap after resolution. rolldown/rolldown#10440 fixed this in rolldown 1.2.1, and Vite 8.3.0 and later require rolldown~1.2.6. So passingkindis now enough, and the resolver does the work itself.What
viteResolve()passeskind: "require-call"for arequire()andkind: "import-statement"for an import.custom["node-resolve"]for Vite 7 and earlier.vite.environments.ssr.pluginContainer.resolveId()instead ofvite.pluginContainer.resolveId(..., { ssr: true }). Both reach the same container. The server-levelpluginContainerforwardskindat runtime, but its type has nokindfield, so the environment's container keeps this typed.Vite 8 releases with rolldown older than 1.2.1 (8.0 and 8.1) stay affected. Updating Vite fixes them.
Test
test/cjs-require.test.ts: a CommonJS package requires a dual-format package (import→index.mjs,require→index.cjs). The test expects therequireentry. Without the fix it fails withexpected 'esm' to be 'cjs'.test/module-fallback.test.tsnow stubenvironments.ssr.pluginContainer. All 37 tests in that file pass.pgrepro (the one in Vite 8 breaks importing pg in Vitest #12984). It fails before and passes after on Vite 8.3.0 and 8.3.4 with Vitest 4.1.11 and 5.0.3. It passes before and after on Vite 7.3.7.🤖 Generated with Claude Code