Skip to content

Commit

Permalink
fix(resolve)!: remove special .mjs handling (#14723)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Oct 23, 2023
1 parent cc6319f commit 2141d31
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
2 changes: 2 additions & 0 deletions docs/guide/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ Also there are other breaking changes which only affect few users.
- Renamed `ResolveWorkerOptions` type to `ResolvedWorkerOptions`
- [[#5657] fix: return 404 for resources requests outside the base path](https://github.com/vitejs/vite/pull/5657)
- 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.
- [[#14723] fix(resolve)!: remove special .mjs handling](https://github.com/vitejs/vite/pull/14723)
- 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.

## Migration from v3

Expand Down
16 changes: 3 additions & 13 deletions packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -987,17 +987,8 @@ export function resolvePackageEntry(
)
}

const resolvedFromExports = !!entryPoint

// if exports resolved to .mjs, still resolve other fields.
// This is because .mjs files can technically import .cjs files which would
// make them invalid for pure ESM environments - so if other module/browser
// fields are present, prioritize those instead.
if (
targetWeb &&
options.browserField &&
(!entryPoint || entryPoint.endsWith('.mjs'))
) {
// handle edge case with browser and module field semantics
if (!entryPoint && targetWeb && options.browserField) {
// check browser field
// https://github.com/defunctzombie/package-browser-field-spec
const browserEntry =
Expand Down Expand Up @@ -1039,8 +1030,7 @@ export function resolvePackageEntry(
}

// fallback to mainFields if still not resolved
// TODO: review if `.mjs` check is still needed
if (!resolvedFromExports && (!entryPoint || entryPoint.endsWith('.mjs'))) {
if (!entryPoint) {
for (const field of options.mainFields) {
if (field === 'browser') continue // already checked above
if (typeof data[field] === 'string') {
Expand Down

0 comments on commit 2141d31

Please sign in to comment.