Skip to content

Commit 6ce6d5c

Browse files
committed
fix(resolve): prioritize module + avoid mutating path when
browser field is present but no match is found fix #1299
1 parent 81e5b61 commit 6ce6d5c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { createFilter } from '@rollup/pluginutils'
2020
import { PartialResolvedId } from 'rollup'
2121
import isBuiltin from 'isbuiltin'
2222

23-
const mainFields = ['browser', 'module', 'jsnext', 'jsnext:main', 'main']
23+
const mainFields = ['module', 'jsnext', 'jsnext:main', 'browser', 'main']
2424

2525
const isDebug = process.env.DEBUG
2626
const debug = createDebugger('vite:resolve-details', {
@@ -432,9 +432,9 @@ function mapWithBrowserField(
432432
([from]) => normalize(from) === normalized
433433
)
434434
if (!foundEntry) {
435-
return normalized
435+
return relativePathInPkgDir
436436
}
437-
return normalize(foundEntry[1])
437+
return foundEntry[1]
438438
}
439439

440440
function normalize(file: string) {

0 commit comments

Comments
 (0)