Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #31240: Adding a recursive addPackagePath function in webpack-config #31264

Merged
merged 21 commits into from Feb 6, 2022
Merged
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6b5b5c8
adding try-catch block to getPackagePath function
neeraj3029 Nov 10, 2021
431d4ff
Merge branch 'canary' into neeraj3029try-catch-getPackagePath
neeraj3029 Nov 16, 2021
08cbd15
adding-dep-paths-recursively
neeraj3029 Nov 19, 2021
47d2a44
adding-types-to-addPackagePath
neeraj3029 Nov 19, 2021
c19053a
removing-extra-line
neeraj3029 Nov 19, 2021
52fa4e0
replacing-_path-with-path
neeraj3029 Nov 19, 2021
735a855
Update webpack-config.ts
neeraj3029 Nov 19, 2021
e8fcd80
fixing-azure-build-error
neeraj3029 Nov 19, 2021
4dfaeab
adding-type-to-set
neeraj3029 Nov 19, 2021
3fee738
Merge branch 'canary' into neeraj3029try-catch-getPackagePath
neeraj3029 Nov 19, 2021
58a4dc0
Merge branch 'canary' into neeraj3029try-catch-getPackagePath
kodiakhq[bot] Nov 25, 2021
fbb3fed
Merge branch 'canary' into neeraj3029try-catch-getPackagePath
sokra Nov 25, 2021
4e56e56
lint-fix
neeraj3029 Nov 27, 2021
2efbb4c
adding-set-to-avoid-multiple-failed-resolution-attempts
neeraj3029 Nov 27, 2021
0fd45f3
Merge branch 'canary' into neeraj3029try-catch-getPackagePath
neeraj3029 Nov 27, 2021
6143b67
Merge branch 'canary' into neeraj3029try-catch-getPackagePath
neeraj3029 Dec 5, 2021
1e4d737
Merge branch 'canary' into neeraj3029try-catch-getPackagePath
neeraj3029 Dec 30, 2021
9bd64a0
Merge branch 'canary' into neeraj3029try-catch-getPackagePath
neeraj3029 Jan 24, 2022
321fef6
Merge branch 'canary' into neeraj3029try-catch-getPackagePath
ijjk Feb 6, 2022
9f4db56
simplify a bit and remove next from paths to match previous
ijjk Feb 6, 2022
700135d
remove un-needed Array.from
ijjk Feb 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 21 additions & 4 deletions packages/next/build/webpack-config.ts
Expand Up @@ -691,9 +691,26 @@ export default async function getBaseWebpackConfig(
}

const getPackagePath = (name: string, relativeToPath: string) => {
const packageJsonPath = require.resolve(`${name}/package.json`, {
paths: [relativeToPath],
})
let packageJsonPath = '';
try {
packageJsonPath = require.resolve(`${name}/package.json`, {
paths: [
relativeToPath
]
});
} catch (_) {
// There are acceptable cases when the package with `name` is not found. e.g. when
// substituting 'react-dom' for '@preact/compat', the 'scheduler' package is not found
// relative to 'react-dom'.
// See: https://github.com/vercel/next.js/issues/31240
console.warn(
`Dependency '${name}' was not found relative to ${relativeToPath}. ` +
`Dependencies declared by the parent package may have changed, or the parent package has ` +
`been substituted for a compatible replacement (such as react-dom and @preact/compat). ` +
`Optimized chunk splitting will be unavailable for '${name}'.`
)
return '';
}
// 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:
Expand All @@ -718,7 +735,7 @@ export default async function getBaseWebpackConfig(
'use-subscription',
require.resolve('next', { paths: [dir] })
),
]
].filter(Boolean)

// Select appropriate SplitChunksPlugin config for this build
const splitChunksConfig: webpack.Options.SplitChunksOptions | false = dev
Expand Down