Skip to content

Commit eac376e

Browse files
authoredMar 23, 2023
perf(resolve): fix browser mapping nearest package.json check (#12550)
1 parent 3f70f47 commit eac376e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed
 

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -827,8 +827,8 @@ export function tryNodeResolve(
827827
!(
828828
ext === '.cjs' ||
829829
(ext === '.js' &&
830-
findNearestPackageData(resolved, options.packageCache)?.data.type !==
831-
'module')
830+
findNearestPackageData(path.dirname(resolved), options.packageCache)
831+
?.data.type !== 'module')
832832
) &&
833833
!(include?.includes(pkgId) || include?.includes(id)))
834834

@@ -1206,7 +1206,7 @@ function tryResolveBrowserMapping(
12061206
const pkg =
12071207
importer &&
12081208
(idToPkgMap.get(importer) ||
1209-
findNearestPackageData(importer, options.packageCache))
1209+
findNearestPackageData(path.dirname(importer), options.packageCache))
12101210
if (pkg && isObject(pkg.data.browser)) {
12111211
const mapId = isFilePath ? './' + slash(path.relative(pkg.dir, id)) : id
12121212
const browserMappedPath = mapWithBrowserField(mapId, pkg.data.browser)

0 commit comments

Comments
 (0)
Please sign in to comment.