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 } } }