Skip to content

Commit

Permalink
fix(config): resolve dynamic import as esm (#11220)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Dec 6, 2022
1 parent 306bed0 commit f8c1ed0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,6 @@ async function bundleConfigFile(
root: path.dirname(fileName),
isBuild: true,
isProduction: true,
isRequire: !isESM,
preferRelative: false,
tryIndex: true,
mainFields: [],
Expand Down Expand Up @@ -1001,8 +1000,15 @@ async function bundleConfigFile(
if (id.startsWith('npm:')) {
return { external: true }
}
let idFsPath = tryNodeResolve(id, importer, options, false)?.id
if (idFsPath && (isESM || kind === 'dynamic-import')) {

const isIdESM = isESM || kind === 'dynamic-import'
let idFsPath = tryNodeResolve(
id,
importer,
{ ...options, isRequire: !isIdESM },
false,
)?.id
if (idFsPath && isIdESM) {
idFsPath = pathToFileURL(idFsPath).href
}
return {
Expand Down

0 comments on commit f8c1ed0

Please sign in to comment.