Skip to content

Instantly share code, notes, and snippets.

@activescott
Last active December 24, 2019 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save activescott/606ef40411d6043e8400c7a47e8846a2 to your computer and use it in GitHub Desktop.
Save activescott/606ef40411d6043e8400c7a47e8846a2 to your computer and use it in GitHub Desktop.
yarn vs npm

Yarn vs NPM

(according to me)

Todo: Review these to make this more comprehensive

Yarn Benefits

There was a time when Yarn's benefits over npm where dramatic. It yielded consistent installs on any host with yarn.lock and it was significantly faster (see https://engineering.fb.com/web/yarn-a-new-package-manager-for-javascript/). However, npm these days is faster (last time I checked) and npm's package-lock.json fixes the consistency issue on npm now too.

yarn run provides a better user experience:

First and foremost, you don't need to type run. Just type yearn <script name> and yarn runs the script.

Passing additional options ot the script is easier in yarn. For example if you have a script named docker-compose to use it in npm you have to type:

npm run docker-compose -- restart

On yarn you type:

yarn docker-compose restart

yarn add

To add a package in npm you must add the --save or --save-dev or it will not be added to package.json. So you might think that npm install

Where as with yarn you type yarn add <packagename> it will always be added to package.json.

yarn upgrade-interactive

Unbelievable that npm didn't add this the next day after it appeared in yarn: npm/npm#18067

workspaces / monorepos

Yarn has native support for mono-repos with workspaces. NPM does not and relies on third party lerna package. Also asked and answerd on SO.

yarn licenses generate-disclaimer

npm benefits

The biggest benefit to npm is that it is universally supported and yarn is not. For example see the GitHub Package Registry documentation and notice how they refer to npm but never yarn. In the vast majority of cases yarn will just work exactly the way that npm does, but not always. And when it doesn't you have a real head scratcher and you're constantly tempted to rever to npm to see if ruling out yarn will resolve the issue.

Alternatives

https://github.com/entropic-dev/entropic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment