From b39ea88e04671181b2a1090cd93e92f4b9bcf7e8 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 19 May 2021 11:12:13 +0200 Subject: [PATCH] restore webpack defaults for managed/immutablePaths --- packages/next/build/webpack-config.ts | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 5a3a59975e6e3..478e32adba22b 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-ignore 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-ignore webpack 5 + webpackConfig.snapshot.managedPaths = [ + path.resolve(match[1], 'unplugged'), + ] + } + } else { + const match = /^(.+?[\\/]node_modules)[\\/]/.exec( + require.resolve('jest-worker') + ) + if (match) { + // @ts-ignore 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-ignore 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-ignore webpack 5 + webpackConfig.snapshot.immutablePaths = [match[1]] + } + } + if (dev) { if (!webpackConfig.optimization) { webpackConfig.optimization = {}