These are the things I learned while setting up a project with Yarn Berry.
- Setting up Next with Yarn Berry
-
Why use it?
- Zero-install: manage dependencies through Git.
- Address node_modules drawbacks: eliminate phantom dependencies and prevent duplicate installations.
-
How to install it
After installing Next.js with TypeScript:
- Remove the existing node_modules folder and package.lock.json file.
rm -rf node_modules rm -rf package.lock.json- Switch to Yarn Berry.
yarn set version berryThis creates a yarnrc.yml file and yarn-(version).cjs inside the .yarn folder.
- To use PnP, change nodeLinker in .yarnrc.yml from node_modules to pnp.
nodeLinker: pnp- Run yarn install.
yarn install- Add these to .gitignore (important!).
.yarn/* !.yarn/cache !.yarn/patches !.yarn/plugins !.yarn/releases !.yarn/sdks !.yarn/versions -
References
[Yarn Berry + VS Code] Applying Yarn Berry, including VS Code settings
Trying PnP (Plug’n’Play) with Yarn 2 and TypeScript
Configuration:
-
Other notes @Moldy (몰디): ESLint and Prettier need configuration. Yarn Berry’s Plug’n’Play approach caused an error where the IDE couldn’t find the ESLint file. (VS Code requires installing the SDK.) Using WebStorm Actions on Save with Yarn Berry (Prettier, ESLint) JetBrains issue WEB-57519
My question
Why install node_modules only to remove it again?
Can’t we set it up correctly from the start??
That’s how I discovered…
Creating a Next.js project with Yarn 2
We can use Next.js manual setup.
That saves the time spent installing node_modules.
Were there any downsides to Yarn Berry here?
Are there options besides Yarn Berry?
There is pnpm.