Moving between projects that use NPM and Yarn typically isn’t a big deal. For the most part, the package dependency managers work almost identical. But one thing that does tend to trip developers up is the subtle command line changes between the two. Often it’s just the case of swapping install/uninstall in NPM to add/remove in Yarn, so here’s a quick cheatsheet for doing just that.
NPM Command | Yarn Command | Description |
---|---|---|
npm install [package-name] | yarn add [package-name] | Installs a package |
npm install [package-name] –save-dev | yarn add [package-name] –dev | Installs a package as a dev dependency |
npm install | yarn OR yarn install | Installs all dependencies inside package.json |
npm uninstall [package-name] | yarn remove [package-name] | Uninstalls a package |
npm uninstall [package-name] –save-dev | yarn remove [package-name] | Uninstalls a package as a dev dependency (Yarn command is the same as uninstall regular dependency) |
npm update | yarn upgrade | Updates all packages |
npm update [package-name] | yarn upgrade [package-name] | Updates a single package |
npm install [package-name] -g | yarn global add [package-name] | Installs a globally accessibly package |
npm uninstall [package-name] -g | yarn global remove [package-name] | Uninstalls a globally accessibly package |
While the above are the main commands that have subtle differences. There are actually some commands that are identical between NPM and Yarn, that you basically just sub out the word npm with yarn on the command line and you are good to go. These are :
NPM Command | Yarn Command | Description |
---|---|---|
npm install –production | yarn install –production | Installs all dependencies in package.json *except* dev dependencies |
npm init | yarn init | Creates a new package.json file / project setup |
npm run | yarn run | Runs scripts from your package.json file |
npm test | yarn test | Runs tests from your package.json file |
npm publish | yarn publish | Publishes your package/td> |
npm cache clean | yarn cache clean | Clears the global package cache |
npm login | yarn login | Logs a user into an package register |
💬 Leave a comment