Skip to content

Commit 2141d31

Browse files
authored
fix(resolve)!: remove special .mjs handling (#14723)
1 parent cc6319f commit 2141d31

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

docs/guide/migration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ Also there are other breaking changes which only affect few users.
133133
- Renamed `ResolveWorkerOptions` type to `ResolvedWorkerOptions`
134134
- [[#5657] fix: return 404 for resources requests outside the base path](https://github.com/vitejs/vite/pull/5657)
135135
- In the past, Vite responded to requests outside the base path without `Accept: text/html`, as if they were requested with the base path. Vite no longer does that and responds with 404 instead.
136+
- [[#14723] fix(resolve)!: remove special .mjs handling](https://github.com/vitejs/vite/pull/14723)
137+
- In the past, when a library `"exports"` field maps to an `.mjs` file, Vite will still try to match the `"browser"` and `"module"` fields to fix compatibility with certain libraries. This behavior is now removed to align with the exports resolution algorithm.
136138

137139
## Migration from v3
138140

packages/vite/src/node/plugins/resolve.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -987,17 +987,8 @@ export function resolvePackageEntry(
987987
)
988988
}
989989

990-
const resolvedFromExports = !!entryPoint
991-
992-
// if exports resolved to .mjs, still resolve other fields.
993-
// This is because .mjs files can technically import .cjs files which would
994-
// make them invalid for pure ESM environments - so if other module/browser
995-
// fields are present, prioritize those instead.
996-
if (
997-
targetWeb &&
998-
options.browserField &&
999-
(!entryPoint || entryPoint.endsWith('.mjs'))
1000-
) {
990+
// handle edge case with browser and module field semantics
991+
if (!entryPoint && targetWeb && options.browserField) {
1001992
// check browser field
1002993
// https://github.com/defunctzombie/package-browser-field-spec
1003994
const browserEntry =
@@ -1039,8 +1030,7 @@ export function resolvePackageEntry(
10391030
}
10401031

10411032
// fallback to mainFields if still not resolved
1042-
// TODO: review if `.mjs` check is still needed
1043-
if (!resolvedFromExports && (!entryPoint || entryPoint.endsWith('.mjs'))) {
1033+
if (!entryPoint) {
10441034
for (const field of options.mainFields) {
10451035
if (field === 'browser') continue // already checked above
10461036
if (typeof data[field] === 'string') {

0 commit comments

Comments
 (0)