Switch npm to yarn

Quick & easy

1 min read
Node Package Management
  • corepack enable
  • yarn set version berry
  • rm package-lock.json
  • update scrips in package.json:
    • npm install -> yarn add
    • npm install --save-dev -> yarn add --dev
    • npm install -D -> yarn add -D
    • npm run <script> -> yarn <script>
    • npm uninstall <package> -> yarn remove <package>
  • if you want to keep node_modules folder:
    • add nodeLinker: node-modules to .yarnrc.yml
  • yarn install
  • commit yarn setup files:
    • .yarn/releases
    • .yarn/plugins
    • .yarn/patches
    • .yarn/sdks
    • .yarn/versions
    • yarn.lock
    • .yarnrc.yml
  • fix .gitignore if needed:
# Yarn Berry
.yarn/*
!.yarn/patches
!.yarn/releases
!.yarn/plugins
!.yarn/sdks
!.yarn/versions

# Optional (if you don’t use nodeLinker: node-modules)
node_modules

# Logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
  • if you want zero-install:
    • commit .yarn/cache/
    • otherwise add .yarn/cache/ to .gitignore