WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 38a8609

Browse files
authored
fix: inconsistentCjsInterop: true should affect dynamic imports as well (#521)
1 parent abc49a3 commit 38a8609

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

packages/vite/src/node/plugins/importAnalysis.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,11 +948,12 @@ export function interopNamedImports(
948948
} = importSpecifier
949949
const exp = source.slice(expStart, expEnd)
950950
if (dynamicIndex > -1) {
951+
const inconsistentCjsInterop = !!config.legacy?.inconsistentCjsInterop
951952
// rewrite `import('package')` to expose the default directly
952953
str.overwrite(
953954
expStart,
954955
expEnd,
955-
`import('${rewrittenUrl}').then(m => (${interopHelperStr})(m.default, 1))` +
956+
`import('${rewrittenUrl}').then(m => (${interopHelperStr})(m.default, ${inconsistentCjsInterop ? 0 : 1}))` +
956957
getLineBreaks(exp),
957958
{ contentOnly: true },
958959
)

0 commit comments

Comments
 (0)