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

Yarn Berry: Switch from from node_modules to PnP #161

Merged
merged 30 commits into from Feb 1, 2022
Merged

Yarn Berry: Switch from from node_modules to PnP #161

merged 30 commits into from Feb 1, 2022

Conversation

kachkaev
Copy link
Owner

@kachkaev kachkaev commented Nov 21, 2021

Continues #160, replaces #29


Key steps:

  1. Edit .yarnrc.yml:

    -nodeLinker: node-modules
    +nodeLinker: pnp
  2. Run

    rm -rf node_modules
    rm -rf cli/node_modules ## specific to this project
  3. Update .gitignore and other *ignore files:

    -node_modules
    +.pnp.*

    It might be worth keeping node_modules for some time if you expect to switch between PnP and non-PnP branches.

  4. Run

    yarn install
    yarn dlx @yarnpkg/sdks vscode
  5. Remove nodeLinker: pnp from .yarnrc.yml (doing this in step 1 breaks yarn install in step 2).

  6. Add require("@rushstack/eslint-patch/modern-module-resolution"); and parserOptions: { tsconfigRootDir: __dirname }, to .eslintrc.js – see https://www.npmjs.com/package/@rushstack/eslint-patch. Thanks to @merceyz for the tip!

  7. Track Picking a different typescript.tsdk from a list / use in a multi-root workspace with yarn2 pnp microsoft/vscode#108866 and don’t use multi-root workspaces in VSCode until resolved

    • Workaround: one VSCode window → only one project folder 🙁
  8. Track yarn2 Vercel build failed - No Next.js version could be detected in your project vercel/vercel#5280 for a permanent fix of Next.js deployment to Vercel

@vercel
Copy link

vercel bot commented Nov 21, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/kachkaev/njt/7qTQ5QxYp6S39Db3nrMUhvBTvmFG
✅ Preview: https://njt-git-yarn-pnp-kachkaev.vercel.app

@merceyz
Copy link

merceyz commented Nov 21, 2021

Hoist ESLint plugins

You can add https://github.com/microsoft/rushstack/tree/9c81203c95dcfab1631e9fd12913c7a3681d7360/stack/eslint-patch to your ESLint config to fix their resolution instead

package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
Comment on lines +5 to +7
styled-components@*:
dependencies:
react-is: "*"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +2 to +4
eslint-module-utils@*:
dependencies:
eslint-import-resolver-node: "*"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kachkaev
Copy link
Owner Author

Great, thanks for your tip @merceyz! Adding require("@rushstack/eslint-patch/modern-module-resolution"); to .eslintrc worked like a charm! I updated the migration instruction in the first comment and mentioned you there.

If you have any other tips, please fell free to share! 🙌

@rauchg
Copy link

rauchg commented Jan 11, 2022

I see you're using Vercel! What are things we could do to support PnP better on our platform, if any? Thanks in advance.

@kachkaev
Copy link
Owner Author

kachkaev commented Jan 12, 2022

👋 @rauchg! Unfortunately Vercel does not currently support Yarn PnP. Here are some links I could dig out while working on this PR:

As a workaround proposed in vercel/vercel#5280 (comment), I had to set FORCE_BUILDER_TAG=canary in the Vercel dashboard. It works, but I guess what it does is setting YARN_NODE_LINKER=node-modules to turn off Yarn PnP.

I hope PnP will get some priority this year because Yarn installs are significantly faster without node_modules. For you at Vercel this means happier customers and smaller infrastructure bills 😁

Looking at the state of my experiment (this PR), I’m somewhat sure that PnP will start setting off in 2022. Tooling support was way worse a year ago when I started, but it’s pretty much there now!

@kachkaev kachkaev marked this pull request as ready for review January 29, 2022 00:31
@kachkaev kachkaev merged commit 16e9950 into main Feb 1, 2022
@kachkaev kachkaev deleted the yarn-pnp branch February 1, 2022 20:56
@kachkaev
Copy link
Owner Author

kachkaev commented Feb 1, 2022

Mission complete! 🕺

https://twitter.com/kachkaev/status/1488630228842917891

@kachkaev kachkaev mentioned this pull request Apr 6, 2022
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants