From bffd564180a7f272a38ec42d2d0b8bf3ee6d24b1 Mon Sep 17 00:00:00 2001 From: Jon Wolfe Date: Thu, 9 Dec 2021 10:59:07 -0500 Subject: [PATCH] Don't choke on frameworks that don't exist - Fixes #31551 --- packages/next/build/webpack-config.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index c50df8b8c0340..aa4f9d4cac77a 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -696,15 +696,19 @@ export default async function getBaseWebpackConfig( } const getPackagePath = (name: string, relativeToPath: string) => { - const packageJsonPath = require.resolve(`${name}/package.json`, { - paths: [relativeToPath], - }) - // Include a trailing slash so that a `.startsWith(packagePath)` check avoids false positives - // when one package name starts with the full name of a different package. - // For example: - // "node_modules/react-slider".startsWith("node_modules/react") // true - // "node_modules/react-slider".startsWith("node_modules/react/") // false - return path.join(packageJsonPath, '../') + try { + const packageJsonPath = require.resolve(`${name}/package.json`, { + paths: [relativeToPath], + }) + // Include a trailing slash so that a `.startsWith(packagePath)` check avoids false positives + // when one package name starts with the full name of a different package. + // For example: + // "node_modules/react-slider".startsWith("node_modules/react") // true + // "node_modules/react-slider".startsWith("node_modules/react/") // false + return path.join(packageJsonPath, '../') + } catch (err) { + return ''; + } } // Packages which will be split into the 'framework' chunk. @@ -723,7 +727,7 @@ export default async function getBaseWebpackConfig( 'use-subscription', require.resolve('next', { paths: [dir] }) ), - ] + ].filter((entry) => Boolean(entry)) // Select appropriate SplitChunksPlugin config for this build const splitChunksConfig: webpack.Options.SplitChunksOptions | false = dev