From ce2d49ab396aa7b4ed582650e569d7f2f6d3ef9f Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 23 Jan 2021 00:20:34 -0500 Subject: [PATCH] fix: file dir resolve should prioritize package.json --- packages/vite/src/node/plugins/resolve.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index 58cd6dbec43966..6b9f036276111c 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -252,16 +252,16 @@ function tryResolveFile( if (fs.existsSync(file)) { const isDir = fs.statSync(file).isDirectory() if (isDir) { - if (tryIndex) { - const index = tryFsResolve(file + '/index', isProduction, false) - if (index) return normalizePath(index) + query - } const pkgPath = file + '/package.json' if (fs.existsSync(pkgPath)) { // path points to a node package const pkg = loadPackageData(pkgPath) return resolvePackageEntry(file, pkg, isProduction) } + if (tryIndex) { + const index = tryFsResolve(file + '/index', isProduction, false) + if (index) return normalizePath(index) + query + } } else { return normalizePath(file) + query }