diff --git a/src/syntax.ts b/src/syntax.ts index 05ecc17..5a15b33 100644 --- a/src/syntax.ts +++ b/src/syntax.ts @@ -74,13 +74,13 @@ export async function isValidNodeImport (id: string, _opts: ValidNodeImportOptio return false } + const pkg = await readPackageJSON(resolvedPath).catch(() => null) + if (pkg?.type === 'module') { return true } + if (resolvedPath.match(/\.(\w+-)?esm?(-\w+)?\.js$/)) { return false } - const pkg = await readPackageJSON(resolvedPath).catch(() => null) - if (pkg?.type === 'module') { return true } - const code = opts.code || await fsp.readFile(resolvedPath, 'utf-8').catch(() => null) || '' return hasCJSSyntax(code) || !hasESMSyntax(code)