“This is the 10th day of my participation in the First Challenge 2022. For details: First Challenge 2022.”
NPM releases and FAQs
Note the basic process and problems encountered in the recent release of the NPM package.
registered
1. Register on NPM website
https:www.npmjs.com/
Copy the code
2. Register on the cli
npm adduser // Enter Username, Password, and Email as prompted
Copy the code
The login
Don’t use email to log in to your website.
npm login // Enter Username, Password, and Email as prompted
Copy the code
Initialize the NPM project
npm init // Enter the project name, version, description, keywords, Github address, and so on
Copy the code
Test the NPM package
Local test
In the same directory as package.json in the NPM project:
NPM link Creates a Symlink from the NPM package to the global fileCopy the code
In the items used for testing:
// Introduce the package into the project. It can be introduced and tested directly in the project
// It works like NPM install, but is localNPM link < your package name >Copy the code
Modify the code in the NPM project. In the test project, you can see the real-time updates of the NPM project and delete local references when they are used up
NPM unlink < your package name >// Similar to NPM uninstall,
Copy the code
Quoted from: local package debugging
The online test
Modify package.json in the test version"version": "0.0.1 - beta",
npm publish --tag=beta // Release beta
npm install @fz/components@beta // Download the beta
Copy the code
Release NPM package
Scoped NPM
If the NPM package is a public, publish --access public. If the NPM package is a public, publish --access publicCopy the code
Not scoped
Such as: brokenwheelCopy the code
After testing the NPM that needs to be published, enter the project root directory and execute the publish command
npm publish
Copy the code
If the following error occursGenerally, it is the first time to register. If you need to verify your email address, you need to issue # login on the official website again and find the prompt at the top. If there is no prompt, refresh it several times and the text prompt as shown in the picture below will appearClick the link, NPM will send a verification email to the mailbox, check and verify in the mailbox, and execute again after the verification is successful
npm publish
Copy the code
An NPM package name duplicate error may occur during this period. The following error is reported
npm ERR! You do not have permission to publish "npmtest". Are you logged in as the correct user?
Copy the code
Change the project name in package.json and publish it again.
The following message is displayed when the publication is successful
To see the NPM package you just released, go to the official website and log in to your project
Download and test the newly released NPM package
Take the NPM package I just released to handle formatting as an example
Download and use are normal. Successful release!
There could be problems
NPM source address problem
Many students in China will point the mirror source of NPM to Taobao. Although the speed is improved, NPM is published on the mirror source of NPM. Therefore, if the following error is reported, please change the source address back to the mirror source of NPM
Error:
npm ERR! 403 403 Forbidden - PUT https://registry.npm.taobao.org/canvas2file - [no_perms] Private mode enable, only admin can publish this module
Copy the code
Fix it:
1, check the current mirror address NPM get registry2NPM config set registry HTTPS://registry.npmjs.org/`
Copy the code
Update published NPM packages
Update the version of this package locally, in two ways
1, NPM version < update_type >2You can also change the version value directly in the project's package.jsonCopy the code
2. Submit to the remote NPM and run the command
npm publish // Publish the NPM package
npm version update_type // Update the package versionThere are three parameters. The current version is1.0. 0
1, patch: indicates a patch// After execution: 1.0.1
2, minor: minor changes// After execution: 1.1.0
3, Major: major version iteration// After execution: 2.0.0
Copy the code