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

Next 12 Module Resolution broken for Yarn 2 PNP #32546

Closed
sicarius97 opened this issue Dec 15, 2021 · 7 comments
Closed

Next 12 Module Resolution broken for Yarn 2 PNP #32546

sicarius97 opened this issue Dec 15, 2021 · 7 comments
Labels
bug Issue was opened via the bug report template.

Comments

@sicarius97
Copy link
Contributor

What version of Next.js are you using?

12.0.7

What version of Node.js are you using?

16.9.0

What browser are you using?

Chrome

What operating system are you using?

Ubuntu, Windows

How are you deploying your application?

next start

Describe the Bug

I upgraded from next 11.1.0 to the most recent next release 12.0.7 after the eslint issues got fixed and found that deps resolution seems to be slightly broken for yarn 2 pnp. Next 11 was mostly compatible with yarn 2 pnp and various other yarn 2 resolution methods, but next 12 seems to have broken that system. I can't confirm that this holds true for all next 12 releases, but has been confirmed on 12.0.7 and 12.0.6. When running my local dev server, these are some of the errors I am getting:

image
image

I have also confirmed in a separate project that next 12 DOES work with yarn 2 nodeLinker resolution mode, but I prefer a zero install method that uses solely yarn cache with no node_modules in pretty much all my projects, that way all deps can be packaged with my repo, which is becoming a more and more popular method with many javascript/nodejs devs with the advent of yarn 2.

Expected Behavior

The expected behavior would be for the nextjs application to compile as normal, as this issue is preventing the whole app from compiling.

To Reproduce

The following steps would allow someone to quickly bootstrap a project like this one:

npm install -g yarn

yarn set version berry

yarn dlx create-next-app .

(If you have to, put the app in a child directory and then re copy paste everything into the parent directory as I dont think my PR that would fix yarn dlx create-next-app . on this repo has been merged. Also make sure version is next 12.0.7)

Ensure that the .yarnrc.yml nodeLinker setting does not have any entry or is set to pnp. Then run the following:

yarn install

yarn dev

@sicarius97 sicarius97 added the bug Issue was opened via the bug report template. label Dec 15, 2021
@sicarius97
Copy link
Contributor Author

Tried some further investigating, though I will need to look more into the pnp api, and found that the virtual mapping appears to be part of the issue. Though, webpack used to have some issues that gave very similar output, so I will also be looking into what is going on with webpack when the dev server starts to see if it gives me any further ideas on why these modules are showing that they cannot be resolved or dont exist. I took a look at the pnp.cjs as well and it looks like pretty much everything is mapped the same as it was in 11.1.0, so I am unsure yet where this issue is stemming from

@rtritto
Copy link

rtritto commented Dec 16, 2021

This issue is related also to yarn v3 (yarn set version berry command will install latest yarn version, currently it's v3).

Related issue: #31812

Temporary workaround: #31812 (comment)

@sicarius97
Copy link
Contributor Author

I did not see the related issue @rtritto mentioned, but the version of yarn I am using is also 3.0.2. I believe all new versions are colloquially referred to as "yarn 2"

@rtritto
Copy link

rtritto commented Dec 18, 2021

yarn v2 and v3 are both versions of yarn berry.

@sicarius97
Copy link
Contributor Author

sicarius97 commented Dec 21, 2021

yarn v2 and v3 are both versions of yarn berry.

@rtritto that's the name of their repo and release cycle, the proper names are yarn 1 or yarn classic and yarn 2 or yarn modern. They refer to all post classic versions as yarn 2 all over their docs and in most of their news releases. Anyway, it doesn't matter, semantics. The point is, yarn (berry or 2 or 3.0.x) pnp resolution is currently broken on next 12

@balazsorban44
Copy link
Member

Seems to be a duplicate of #32115

kodiakhq bot pushed a commit that referenced this issue Jan 11, 2022
x-ref [#31552 ](#31552)
x-ref #32115
x-ref #32546
x-ref #32721

Since this PR #31455 is merged, `enhanced-resolve` dependency's resolved field is changed which caused broken yarn pnp.
I am not sure how this field has been changed or this is intentional or not 
When I install webpack locally, `enhanced-resolve`'s resolved field in lock file is always `registry.yarnpkg.com` not `codeload.github.com`

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`


Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Feb 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

3 participants