Skip to content

Commit

Permalink
fix(vite-node): fix isValidNodeImport to check `pkg.type === "modul…
Browse files Browse the repository at this point in the history
…e"` first
  • Loading branch information
hi-ogawa committed Mar 22, 2024
1 parent fee7d8b commit bce167b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/vite-node/src/externalize.ts
Original file line number Diff line number Diff line change
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 bce167b

Please sign in to comment.