diff --git a/packages/plugin-react/src/index.ts b/packages/plugin-react/src/index.ts index 2cc9eaab5a5f75..f94737b620eee5 100644 --- a/packages/plugin-react/src/index.ts +++ b/packages/plugin-react/src/index.ts @@ -52,6 +52,9 @@ export default function viteReact(opts: Options = {}): PluginOption[] { let skipFastRefresh = opts.fastRefresh === false let skipReactImport = false + // The dir where pre-bundled deps is stored + let cacheDir: string + const useAutomaticRuntime = opts.jsxRuntime !== 'classic' const userPlugins = opts.babel?.plugins || [] @@ -78,6 +81,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] { }) isProduction = config.isProduction skipFastRefresh ||= isProduction || config.command === 'build' + cacheDir = config.cacheDir as string const jsxInject = config.esbuild && config.esbuild.jsxInject if (jsxInject && importReactRE.test(jsxInject)) { @@ -107,6 +111,11 @@ export default function viteReact(opts: Options = {}): PluginOption[] { filepath.match(fileExtensionRE) || [] + // Pre-bundle deps should not be transformed there. #5438 + if (id.startsWith(cacheDir)) { + return + } + if (/\.(mjs|[tj]sx?)$/.test(extension)) { const plugins = [...userPlugins] diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 4d6d4436b4248b..2f87a0bbb55af4 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -520,7 +520,8 @@ export function combineSourcemaps( const useArrayInterface = sourcemapList.slice(0, -1).find((m) => m.sources.length !== 1) === undefined if (useArrayInterface) { - map = remapping(sourcemapList, () => null, true) + // We cann't exclude sourcesContent there. #5438 + map = remapping(sourcemapList, () => null, false) } else { map = remapping( sourcemapList[0], @@ -531,7 +532,7 @@ export function combineSourcemaps( return { ...nullSourceMap } } }, - true + false ) } if (!map.file) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e86f24fd601903..f69fe06b35edf0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7183,7 +7183,7 @@ packages: dev: true /pvutils/1.0.17: - resolution: {integrity: sha512-wLHYUQxWaXVQvKnwIDWFVKDJku9XDCvyhhxoq8dc5MFdIlRenyPI9eSfEtcvgHgD7FlvCyGAlWgOzRnZD99GZQ==} + resolution: {integrity: sha1-rePHTf5xeJRP5EgGYmvS4knZlr8=} engines: {node: '>=6.0.0'} dev: true