Movatterモバイル変換


[0]ホーム

URL:


Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Migrating from npm

Migrating from npm should be a fairly easy process for most users. Yarn canconsume the samepackage.json format as npm, and can install any package fromthe npm registry.

If you want to try Yarn out on your existing npm project, just try running:

yarn

This will lay out yournode_modules folder using Yarn’s resolution algorithmthat is compatible with thenode.js module resolution algorithm.

If you get an error, please check for an existing issue or report it to theYarn issue tracker.

When you run eitheryarn oryarn add <package>, Yarn will generate ayarn.lock file within the root directory of your package. You don’t need to read or understand this file - just check it into source control. When other people start using Yarn instead ofnpm, theyarn.lock file will ensure that they get precisely the same dependencies as you have.

In most cases, runningyarn oryarn add for the first time will just work. In some cases, the information in apackage.json file is not explicit enough to eliminate dependencies, and the deterministic way that Yarn chooses dependencies will run into dependency conflicts. This is especially likely to happen in larger projects where sometimesnpm install does not work and developers are frequently removingnode_modules and rebuilding from scratch. If this happens, try usingnpm to make the versions of dependencies more explicit, before converting to Yarn.

As of Yarn 1.7.0, you canimport your package-lock.json state, generated bynpm to Yarn, by usingyarn import.

Other developers on the project can keep usingnpm, so you don’t need to get everyone on your project to convert at the same time. The developers usingyarn will all get exactly the same configuration as each other, and the developers usingnpm may get slightly different configurations, which is the intended behavior ofnpm.

Later, if you decide that Yarn is not for you, you can just go back to usingnpm without making any particular changes. You can delete your oldyarn.lock file if nobody on the project is using Yarn any more but it’s not necessary.

If you are using annpm-shrinkwrap.json file right now, be aware that you mayend up with a different set of dependencies. Yarn does not support npmshrinkwrap files as they don’t have enough information in them to power Yarn’smore deterministic algorithm. If you are using a shrinkwrap file it may be easierto convert everyone working on the project to use Yarn at the same time. Simply removeyour existingnpm-shrinkwrap.json file and check in the newly createdyarn.lock file.

CLI commands comparison

npm (v5)Yarn
npm installyarn add
(N/A)yarn add --flat
(N/A)yarn add --har
npm install --no-package-lockyarn add --no-lockfile
(N/A)yarn add --pure-lockfile
npm install [package] --saveyarn add [package]
npm install [package] --save-devyarn add [package] --dev
(N/A)yarn add [package] --peer
npm install [package] --save-optionalyarn add [package] --optional
npm install [package] --save-exactyarn add [package] --exact
(N/A)yarn add [package] --tilde
npm install [package] --globalyarn global add [package]
npm update --global                  yarn global upgrade                    
npm rebuildyarn add --force
npm uninstall [package]yarn remove [package]
npm cache cleanyarn cache clean [package]
rm -rf node_modules && npm install  yarn upgrade                          
npm version major                    yarn version --major                  
npm version minor                    yarn version --minor                  
npm version patch                    yarn version --patch                  
npm explain [package]                yarn why [package]                  
npm audit [package]                yarn audit [package]                



[8]ページ先頭

©2009-2025 Movatter.jp