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

Not working with Yarn pnpm strategy #65757

Open
coreyward opened this issue May 14, 2024 · 3 comments
Open

Not working with Yarn pnpm strategy #65757

coreyward opened this issue May 14, 2024 · 3 comments
Labels
bug Issue was opened via the bug report template. Module Resolution Module resolution (CJS / ESM, module resolving) Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@coreyward
Copy link

coreyward commented May 14, 2024

Link to the code that reproduces this issue

https://github.com/coreyward/next-yarn-pnpm-issue

To Reproduce

Run yarn dev in the linked repo root, then open the app at localhost:3000. This will trigger the following error:

Error: Invariant: Expected relative import to start with "next/", found "package/dist/server/future/route-modules/pages/module.compiled"
at [Symbol.replace] ()
at String.replaceAll ()

Screenshot 2024-05-14 at 2 01 12 PM

Current vs. Expected behavior

Next works fine when using the legacy node_modules approach for installing dependencies, and seems to have support for the Plug-N-Play strategy of pnpm, but it does not seem to account for Yarn’s hybrid pnpm strategy which is described as follows:

node-modules will be created using symlinks and hardlinks to a global content-addressable store.

The issue seems to come about in the load-entrypoint, which seems to make unsafe assumptions about where dependencies are located on disk relative to the project. The specific error is coming from Next.js here:

// Verify that the relative import is relative to the `next` package. This
// will catch cases where the constants at the top of the file were not
// updated after the file was moved.
if (!relative.startsWith('next/')) {
throw new Error(
`Invariant: Expected relative import to start with "next/", found "${relative}"`
)
}

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.4.0
Binaries:
  Node: 20.11.0
  npm: 10.2.4
  Yarn: 4.2.2
  pnpm: N/A
Relevant Packages:
  next: 14.3.0-canary.62 // Latest available version is detected (14.3.0-canary.62).
  eslint-config-next: N/A
  react: 19.0.0-beta-4508873393-20240430
  react-dom: 19.0.0-beta-4508873393-20240430
  typescript: 5.1.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Module Resolution, Runtime

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local)

Additional context

This may be related to #16471.

@coreyward coreyward added the bug Issue was opened via the bug report template. label May 14, 2024
@github-actions github-actions bot added Module Resolution Module resolution (CJS / ESM, module resolving) Runtime Related to Node.js or Edge Runtime with Next.js. labels May 14, 2024
@Yukigamine
Copy link

I have been seeing this issue with Yarn 4.x–also using pnpm.

Downgrading to Yarn 3.x is how I fixed the issue in my projects.

@coreyward
Copy link
Author

@Yukigamine If you're able to use one of the other strategies it works (node-modules or pnp), but they both have other drawbacks (especially pnp).

@Yukigamine
Copy link

So the issue seems to be related specifically to the pnpm strategy using Yarn 4.x in Next.JS projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Module Resolution Module resolution (CJS / ESM, module resolving) Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

No branches or pull requests

2 participants