Ⅰ. Yarn
Tool introduction:
1. What is yarn
a tool:
Yarn
It is facebook
a resource package management tool released by to replace npm
, which is a fast, reliable and safe dependency management tool, and a new JavaScript
resource package management tool (under the spit: the biggest disadvantage is that it needs to be npm
installed through );
2. Advantages of yarn
comparison npm
tools:
One, npm
aspect:
A. npm install
Very slow:
In particular, it takes a long time to wait for a new project to be pulled down, and install
it will still be the same when it is restarted;
In deletion node_modules
, it will not be successfully deleted due to other reasons;
B. The version cannot be kept consistent:
For the same project, the module version cannot be kept consistent during installation, which is due to package.json
the version number in the file;
C. The installation error is overwritten:
When installing, the packages will be downloaded and installed at the same time, at some point in the middle, a package throws an error, but npm
will continue to download and install the package;
Second, yarn
aspects:
A. Faster installation:
Offline cache, yarn
which caches each downloaded package, so there is no need to download it again when it is used again;
Also utilizes parallel downloads to maximize resource utilization, so installs are faster.
B. The installation version is the same:
Before the code is executed, Yarn
the integrity of each installation package is verified by an algorithm;
And in order to prevent pulling different versions, Yarn
there is a lock file (lock file)
that records the version number of the module that is exactly installed;
C. Concise semantics:
yarn
Changed some npm 命令
names, e.g. yarn add/remove
, to be clearer than npm
the original ;install/uninstall
3. Reasons for wanting to download and use the yarn
management vue
project:
First, because when using npm
the tool to manage vue
the project, an error ( 但错误原因没找到
) is reported:
npm ERR! ENOTEMPTY: directory not empty, rename '/usr/local/lib/node_modules/webpack' -> '/usr/local/lib/node_modules/.webpack-ENG41nb9'
// The overall code of the error is:
npm ERR! code ENOTEMPTY
npm ERR! syscall rename
npm ERR! path /usr/local/lib/node_modules/webpack
npm ERR! dest /usr/local/lib/node_modules/.webpack-ENG41nb9
npm ERR! errno -66
npm ERR! ENOTEMPTY: directory not empty, rename '/usr/local/lib/node_modules/webpack' -> '/usr/local/lib/node_modules/.webpack-ENG41nb9'
npm ERR! A complete log of this run can be found in:
Second, when using yarn
the tool to manage vue
the project, no error is reported;
Ⅱ. Steps to Vue
install in the project Yarn
:
1. yarn
The command to install:
npm install -g yarn
2. VSCode
Check yarn
the version in: 报错
:
If there is an error, please continue to read in order, if there is no error, just skip 3、
to read;
First, the error message is:
yarn 无法加载文件 “C:\Users\admin\AppData\Roaming\npm\yarn.ps1,因为在此系统上禁止运行脚本
Second, the overall error message is:
Third, but in cmd
the command, no error is reported:
Fourth, the solution to this problem is:
// Please see the article at this address:
https://blog.csdn.net/weixin_43405300/article/details/131533816?spm=1001.2014.3001.5501
3. VSCode
Check yarn
the version in: 未报错
:
First, yarn
there is no problem viewing the version:
In the VScode environment, enter the command: yarn --version
, the displayed result is:1.22.19
Second, but at this time, if you enter yarn run serve
the command directly, it will have no effect:
4. Execute the command:yarn install
5. Execute the command:yarn run serve
// At this point, it has successfully run, and there is no problem with access;
Ⅲ. Summary:
First, where there is something wrong or inappropriate, please give me some pointers and exchanges!
Second, if you are interested, you can pay more attention to this column (Vue (Vue2+Vue3) interview must-have column):https://blog.csdn.net/weixin_43405300/category_11525646.html?spm=1001.2014.3001.5482