From e8f8d30480fe5f4a6871c3bcbc1ed69cbe4ad3c6 Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Sun, 26 Jun 2022 19:31:27 +0900 Subject: [PATCH] fix(optimizer): only run require-import convertion if it was called by require --- packages/vite/src/node/optimizer/esbuildDepPlugin.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts index 09866eb300c2a3..8803ae3a1f5c48 100644 --- a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts +++ b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts @@ -118,10 +118,16 @@ export function esbuildDepPlugin( const resolved = await resolve(id, importer, kind) if (resolved) { - // here it is not set to `external: true` to convert `require` to `import` + if (kind === 'require-call') { + // here it is not set to `external: true` to convert `require` to `import` + return { + path: resolved, + namespace: externalWithConversionNamespace + } + } return { path: resolved, - namespace: externalWithConversionNamespace + external: true } } }