Skip to content

Commit

Permalink
perf(resolve): fix browser mapping nearest package.json check (#12550)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Mar 23, 2023
1 parent 3f70f47 commit eac376e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/vite/src/node/plugins/resolve.ts
Expand Up @@ -827,8 +827,8 @@ export function tryNodeResolve(
!(
ext === '.cjs' ||
(ext === '.js' &&
findNearestPackageData(resolved, options.packageCache)?.data.type !==
'module')
findNearestPackageData(path.dirname(resolved), options.packageCache)
?.data.type !== 'module')
) &&
!(include?.includes(pkgId) || include?.includes(id)))

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

0 comments on commit eac376e

Please sign in to comment.