Skip to content

Commit 6fb1528

Browse files
authored
fix(vite-node): fix isValidNodeImport to check "type": "module" first (#5416)
1 parent 16bacfa commit 6fb1528

File tree

8 files changed

+244
-103
lines changed

8 files changed

+244
-103
lines changed

packages/vite-node/src/externalize.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ async function isValidNodeImport(id: string) {
6161
if (extension !== '.js')
6262
return false
6363

64-
if (/\.(\w+-)?esm?(-\w+)?\.js$|\/(esm?)\//.test(id))
65-
return false
66-
6764
id = id.replace('file:///', '')
6865

6966
const package_ = await findNearestPackageData(dirname(id))
7067

7168
if (package_.type === 'module')
7269
return true
7370

71+
if (/\.(\w+-)?esm?(-\w+)?\.js$|\/(esm?)\//.test(id))
72+
return false
73+
7474
const code = await fsp.readFile(id, 'utf8').catch(() => '')
7575

7676
return !ESM_SYNTAX_RE.test(code)

0 commit comments

Comments
 (0)