-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
[12.0.4-canary.2], Preact - Local dev server fails with Error: Cannot find module 'scheduler/package.json' #31240
Comments
Hi @ijjk @elliottsj, I think concerns PR #21048 Should |
@neeraj3029 Can you provide a full repro? Which package manager are you using? |
Sure, I'm using yarn. Edit: I am using |
Dependencies:
|
Ah, I see. The override of I am not sure if Vercel wants to officially support the use case of replacing the As a workaround, you could define a webpack config in |
Looks like Preact is supported by Next.js based on the presence of the example project. I threw together a rough patch which may or may not work: --- a/packages/next/build/webpack-config.ts
+++ b/packages/next/build/webpack-config.ts
@@ -755,9 +755,24 @@ 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 (error) {
+ // 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:
@@ -782,7 +797,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 Feel free to test it out and/or submit it as a pull request. |
Catching the error works. I'll share a PR too in some time! |
Hi @elliottsj, I was trying to do a workaround at my end while the PR is still in review. It seems mutating the In my mind, I think shifting this array to |
Makes sense to me 👍 |
Temp workaround until vercel/next.js#31240 gets fixed
Temporary workaround for vercel/next.js#31240
I have the same issue. My workaround until this is fixed is installing |
This actually seems to be an issue in the |
This is indeed not an issue with the This PR #31264 tries to fix this issue, it'll be great to have reviews on this |
try to get rid of explicit 'scheduler' dependency, see vercel/next.js#31240 same with babel stuff
try to get rid of explicit 'scheduler' dependency, see vercel/next.js#31240 same with babel stuff
try to get rid of explicit 'scheduler' dependency, see vercel/next.js#31240 same with babel stuff
try to get rid of explicit 'scheduler' dependency, see vercel/next.js#31240 same with babel stuff
try to get rid of explicit 'scheduler' dependency, see vercel/next.js#31240 same with babel stuff
…onfig (#31264) Fixes: #31240 Closes: #32324 Adding a try-catch block to handle situations when packages are found at relative path in getPackagePath function. This is likely to occur when using `preact` instead of `react-dom`, as `scheduler` package will not be found wrt `react-dom` ## Bug - [x] Related issues linked using `fixes #31240` Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
Hi, this has been updated in |
…pack-config (vercel#31264) Fixes: vercel#31240 Closes: vercel#32324 Adding a try-catch block to handle situations when packages are found at relative path in getPackagePath function. This is likely to occur when using `preact` instead of `react-dom`, as `scheduler` package will not be found wrt `react-dom` ## Bug - [x] Related issues linked using `fixes vercel#31240` Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
What version of Next.js are you using?
12.0.4-canaray.2 to 12.0.4-canaray.4
What version of Node.js are you using?
14.17.6
What browser are you using?
chrome
What operating system are you using?
macOS
How are you deploying your application?
.
Describe the Bug
Local dev server stops with an error:
Error: Cannot find module 'scheduler/package.json'
.I assume this comes in relation with the recent changes in this line in webocket-config.js.
I believe we
scheduler
must be removed fromtopLevelFrameworkPaths
to make it work correctly.Complete error:
To Reproduce
Package manager: yarn
dependencies:
Upgrade next.js to version >= 12.0.4-canary.2.
The text was updated successfully, but these errors were encountered: