This is the 9th day of my participation in Gwen Challenge
introduce
I believe that many front-end brothers in work have encountered many similar problems:
- Node versions do not match or conflict
- Corporate NPM sources and public sources switch frequently
- Projects depend on slow downloads/startup/packaging
I study and love Python, so the first thing that comes to mind is virtual environments and Conda
Following this idea, I found NVM and then KNEW NRM
Finally approved PNPM in NPM/YARN/PNPM (but with a bit of a bug)
nvm
A node version management tool, the address is github.com/nvm-sh/nvm
For Windows, the address is github.com/coreybutler…
Note that the two commands are different
nrm
It is very similar to NVM in usage, but it is used to manage NPM sources and can be easily switched
Address for github.com/Pana/nrm
Note that the latest version of NRM will cause errors under Windows. I recommend installing the historical version (see the actual process below).
pnpm
Package management tools, this is no more to say, there is a Chinese address www.pnpm.cn/
use
Install node using NVM
The first step is to uninstall the node that has been installed
Step 2: Download the latest installation package from the official website. The installation version is recommended
The third step is to run the installation file. The operation is very simple and will not be repeated
Step 4: Query the current available Node version. Take Windows as an example:
nvm list available
Copy the code
Step 5: Install the specified Node version:
nvm install 14.17.0
Copy the code
If the download is slow or fails in this process, the authors provide us with a very simple setup:
nvm node_mirror https://npm.taobao.org/mirrors/node/
nvm npm_mirror https://npm.taobao.org/mirrors/npm/
Copy the code
Finally, activate the node version you just downloaded:
nvm use 14.17.0
Copy the code
If you want to see which versions you have installed, use NVM LS
Here is a brief description of the problem I encountered. After the first installation, the NPM command cannot be used
My solution is to remove the existing nodejs folder after uninstallation and reinstall it. The problem is resolved. If any of you are in the same situation, please try this first
Use NRM to manage NPM sources
NRM installation is very simple:
npm install -g nrm@1.1.0
Copy the code
Version 1.1.0 can be used normally in Windows, and problems of the latest version do not occur
After using NVM, the operation of NRM can be similar:
# add NRM test http://my/npm/ # add NRM test # add NRM test # add NRM test # add NRM test # add NRM test # add NRM testCopy the code
The specific commands are detailed in the author’s Github repository, but again, the official documentation is better than anything else in most cases
Use PNPM for package management
PNPM installation is the same as NRM:
npm install -g pnpm
Copy the code
The operation of package management is much the same, here mainly explains the two most satisfied with the author of this obsessive-compulsive disorder:
- PNPM’s dependencies are kept in the same place, just links under the project
- PNPM dependency structures are not tiled
When using PNPM to package your project, you ran into an unexpected problem: some dependencies were lost
I found the relevant explanation in Github Issues, so I did not translate it, and directly posted the address
conclusion
- Node versioning is a must
- Package management tools also need to wait and see, cooperate with the team is the most important, do not be unique