diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 5a3a59975e6e36..c8879eb86939cc 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -1247,6 +1247,47 @@ export default async function getBaseWebpackConfig( // webpack 5 no longer polyfills Node.js modules: if (webpackConfig.node) delete webpackConfig.node.setImmediate + // Due to bundling of webpack the default values can't be correctly detected + // This restores the webpack defaults + // @ts-expect-error webpack 5 + webpackConfig.snapshot = {} + if (process.versions.pnp === '3') { + const match = /^(.+?)[\\/]cache[\\/]jest-worker-npm-[^\\/]+\.zip[\\/]node_modules[\\/]/.exec( + require.resolve('jest-worker') + ) + if (match) { + // @ts-expect-error webpack 5 + webpackConfig.snapshot.managedPaths = [ + path.resolve(match[1], 'unplugged'), + ] + } + } else { + const match = /^(.+?[\\/]node_modules)[\\/]/.exec( + require.resolve('jest-worker') + ) + if (match) { + // @ts-expect-error webpack 5 + webpackConfig.snapshot.managedPaths = [match[1]] + } + } + if (process.versions.pnp === '1') { + const match = /^(.+?[\\/]v4)[\\/]npm-jest-worker-[^\\/]+-[\da-f]{40}[\\/]node_modules[\\/]/.exec( + require.resolve('jest-worker') + ) + if (match) { + // @ts-expect-error webpack 5 + webpackConfig.snapshot.immutablePaths = [match[1]] + } + } else if (process.versions.pnp === '3') { + const match = /^(.+?)[\\/]jest-worker-npm-[^\\/]+\.zip[\\/]node_modules[\\/]/.exec( + require.resolve('jest-worker') + ) + if (match) { + // @ts-expect-error webpack 5 + webpackConfig.snapshot.immutablePaths = [match[1]] + } + } + if (dev) { if (!webpackConfig.optimization) { webpackConfig.optimization = {}