From 8e866c3459c04163bb59dd56469f8468add899b3 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Mon, 19 Sep 2022 13:58:59 +0200 Subject: [PATCH] fix(isValidNodeImport): check `type: module` before other detections fix issue with `swiper` --- src/syntax.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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)