vercel / vercel/next.js

Not working with Yarn pnpm strategy

Open
#65,757 15 comments 15 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Module Resolution Runtime
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

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:

https://github.com/vercel/next.js/blob/9d16112e28978aa1beed167f018ae29db607e035/packages/next/src/build/load-entrypoint.ts#L63-L70

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with yarn dev in the linked next-yarn-pnpm-issue repository, then inspect packages/next/src/build/load-entrypoint.ts around lines 63-70. Compare the path assumptions with Yarn’s hybrid pnpm nodeLinker behavior and verify that both next dev and next build work with that setup without the reported invariant error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js
Domain
backend, build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.