Skip to content

Commit

Permalink
restore webpack defaults for managed/immutablePaths
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed May 19, 2021
1 parent 25096df commit f07d005
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down

0 comments on commit f07d005

Please sign in to comment.