Skip to content

Commit

Permalink
Don't choke on frameworks that don't exist - Fixes vercel#31551
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanWolfe committed Dec 11, 2021
1 parent ac82da2 commit 45a1107
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions packages/next/build/webpack-config.ts
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 45a1107

Please sign in to comment.