Skip to content

Commit

Permalink
fix(vite-node): fix isValidNodeImport to check "type": "module" f…
Browse files Browse the repository at this point in the history
…irst (#5416)
  • Loading branch information
hi-ogawa committed Mar 26, 2024
1 parent 16bacfa commit 6fb1528
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 103 deletions.
6 changes: 3 additions & 3 deletions packages/vite-node/src/externalize.ts
Expand Up @@ -61,16 +61,16 @@ async function isValidNodeImport(id: string) {
if (extension !== '.js')
return false

if (/\.(\w+-)?esm?(-\w+)?\.js$|\/(esm?)\//.test(id))
return false

id = id.replace('file:///', '')

const package_ = await findNearestPackageData(dirname(id))

if (package_.type === 'module')
return true

if (/\.(\w+-)?esm?(-\w+)?\.js$|\/(esm?)\//.test(id))
return false

const code = await fsp.readFile(id, 'utf8').catch(() => '')

return !ESM_SYNTAX_RE.test(code)
Expand Down

0 comments on commit 6fb1528

Please sign in to comment.