What is the yarn equivalent of npm install?

Cheat Sheet — What you need to know

  • <span class="markup--strong markup--li-strong" style="font-weight: bold;">npm install</span> === <span class="markup--strong markup--li-strong" style="font-weight: bold;">yarn</span>
    Install is the default behavior.
  • <span class="markup--strong markup--li-strong" style="font-weight: bold;">npm install taco --save</span> === <span class="markup--strong markup--li-strong" style="font-weight: bold;">yarn add taco</span>
    The Taco package is saved to your package.jsonimmediately.
  • <span class="markup--strong markup--li-strong" style="font-weight: bold;">npm uninstall taco --save</span> === <span class="markup--strong markup--li-strong" style="font-weight: bold;">yarn remove taco</span>
    —-savecan be defaulted in NPM by npm config set save true but this is non-obvious to most developers. Adding and removing from package.jsonis default in Yarn.
  • <span class="markup--strong markup--li-strong" style="font-weight: bold;">npm install taco --save-dev</span> === <span class="markup--strong markup--li-strong" style="font-weight: bold;">yarn add taco --dev</span>
  • <span class="markup--strong markup--li-strong" style="font-weight: bold;">npm update --save</span> === <span class="markup--strong markup--li-strong" style="font-weight: bold;">yarn upgrade</span>
    Great call on upgrade vs update, since that is exactly what it is doing! Version number moves, upgrade is happening!
    *WARNING* <a class="markup--anchor markup--li-anchor" style="background-position: 0px 0px; background-repeat: initial; -webkit-tap-highlight-color: rgba(0, 0, 0, 0.54);" href="https://github.com/npm/npm/issues/13555" target="_blank" rel="noopener noreferrer" data-href="https://github.com/npm/npm/issues/13555">n</a>pm update --save seems to be kinda broken in 3.11
  • <span class="markup--strong markup--li-strong" style="font-weight: bold;">npm install [email protected] --save</span> === <span class="markup--strong markup--li-strong" style="font-weight: bold;">yarn add taco</span>
  • <span class="markup--strong markup--li-strong" style="font-weight: bold;">npm install taco --global</span> === <span class="markup--strong markup--li-strong" style="font-weight: bold;">yarn global add taco</span>
    As always, use global flag with care.

 

Reference:
https://shift.infinite.red/npm-vs-yarn-cheat-sheet-8755b092e5cc

Share this article

Leave a Reply

Your email address will not be published.

Scroll to Top