Skip to content

Commit f8c1ed0

Browse files
authoredDec 6, 2022
fix(config): resolve dynamic import as esm (#11220)
1 parent 306bed0 commit f8c1ed0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed
 

‎packages/vite/src/node/config.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,6 @@ async function bundleConfigFile(
973973
root: path.dirname(fileName),
974974
isBuild: true,
975975
isProduction: true,
976-
isRequire: !isESM,
977976
preferRelative: false,
978977
tryIndex: true,
979978
mainFields: [],
@@ -1001,8 +1000,15 @@ async function bundleConfigFile(
10011000
if (id.startsWith('npm:')) {
10021001
return { external: true }
10031002
}
1004-
let idFsPath = tryNodeResolve(id, importer, options, false)?.id
1005-
if (idFsPath && (isESM || kind === 'dynamic-import')) {
1003+
1004+
const isIdESM = isESM || kind === 'dynamic-import'
1005+
let idFsPath = tryNodeResolve(
1006+
id,
1007+
importer,
1008+
{ ...options, isRequire: !isIdESM },
1009+
false,
1010+
)?.id
1011+
if (idFsPath && isIdESM) {
10061012
idFsPath = pathToFileURL(idFsPath).href
10071013
}
10081014
return {

0 commit comments

Comments
 (0)
Please sign in to comment.