Created By JishuBao on 2019-03-08 12:38:22
Recently revised in 2019-03-08 12:38:22
Welcome to the gold digging world of technology treasure, your star is the biggest motivation for me to write articles! Making the address
Article Introduction:
1. Abstract: What is NPM?
2. How to publish your own NPM package?
3. Post bug compilations
Abstract: What is NPM?
NPM is a well-known package management tool for javascript, which is a landmark product of front-end modularization. Simply put, it is through NPM download module, reuse the existing code, improve work efficiency
2. How to publish a NPM package of your own
1. Create an NPM account
Here NPM register account address, username account password Email after registration, verify the following email address.
2. Initialize a simple project release
A. Create a local folder, for example, JishuBao
B. Run the $CD JishuBao command to access the directory
C. Run NPM init to initialize the project. Enter all the way by default.
$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
package name: (jishubao)
version: (1.0. 0)
description: a test npm publish
entry point: (index.js)
test command:
git repository:
keywords:
author: jishubao
license: (ISC)
About to write to E:\MyProject\JishuBao\package.json:
{
"name": "jishubao"."version": "1.0.0"."description": "a test npm publish"."main": "index.js"."scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "jishubao"."license": "ISC"
}
Is this ok? (yes) y
Copy the code
Description of the default fields: name: indicates the name of the published package. The default value is the name of the upper-level folder. Must not be the same as the package name in the current NPM. Package names must not have uppercase letters/Spaces/slippage! Version: The version of your package. The default is1.0. 0. There are a series of rules for the version number of the NPM package. The version number of the module is in the format of X.Y.Z, which is embodied as follows:1Fix bugs, minor changes, add Z.2, added new features, backward compatibility, added y3X description: mian: entry file. The default file is index. js, which can be modified into its own file. Scripts: contains various script execution commands. License: Open Source file license, or MIT, if you need it.Copy the code
D. Create a file named index.js in the JishuBao folder and simply write the contents.
!function(){
console.log('This is the NPM package released by Techcrunch.'); } ()Copy the code
3. If the package is released for the first time (non-first time can be ignored);
Enter NPM adduser in the terminal, prompting you to enter your account, password and email address, and then prompt you to create successfully, as shown in the following figure.
If NPM adduser succeeds, you are already logged in, so skip step 4.
$ npm adduser
Username: user.name(your registered user name)Password: user.password(your password to register)Email: (this IS public) 2459666474@qq.com(own email address) Loggedin as wjb666 on https://registry.npmjs.org/.(success prompt)
Copy the code
The last line shows the login information, followed by the user name as. The source ADDRESS follows on
4. It is not the first time to send a package
Enter NPM login on the terminal, then enter your account and password, and email address to login. The result is the same as step 3.
5, NPM publish publish
Successful release:
$NPM publish (--access public) publish private package1.0. 0
Copy the code
Note: If there is some private code in the project that you do not want to publish to NPM, you can write it to.gitignore or.npmignore and the upload will be ignored
6. Query published packages
Jishubao’s NPM package is now available
7. Installation and use
Same as other packages. Clear the folder you just left.
$ npm install jishubao --save-dev
npm WARN saveError ENOENT: no such file or directory, open 'E:\MyProject\JishuBao\package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open 'E:\MyProject\JishuBao\package.json'
npm WARN JishuBao No description
npm WARN JishuBao No repository field.
npm WARN JishuBao No README data
npm WARN JishuBao No license field.
+ jishubao@1.0. 0
added 1 package in 1.577s
Copy the code
8. How to undo a published package
The terminal executes NPM unpublish
Such as:
1. NPM unpublish [email protected] deletes a release
2, NPM unpublish z-tool –force unpublish z-tool –force
But unpack recommended usage:
NPM unpublish’s recommended alternative: NPM deprecate[@] Using this command will not cancel existing packages in the community, but will warn anyone attempting to install the package in the future. For example: NPM DEPRECate Z-tool ‘This package I no longer maintain
[note] If a permission error is reported, add –force
3. Mistakes
1. You need to increase the version number
#1Sh -neverleave:z-tool neverleave$NPM publish NPM ERR! publish Failed PUT400
npm ERR! code E400
npm ERR! deprecations must be strings : z-tool
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/neverleave/.npm/_logs/2018-11-23T10_52_01_742Z-debug.log
sh-neverleave:z-tool neverleave$ npm publish
#2Sh -neverleave:z-tool neverleave$NPM publish NPM ERR! publish Failed PUT403
npm ERR! code E403
npm ERR! You cannot publish over the previously published versions: 1.03.. : z-tool
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/neverleave/.npm/_logs/2018-11-23T11_24_57_662Z-debug.log
sh-neverleave:z-tool neverleave$
Copy the code
2. NPM publish failed
NPM publish –access public
#1Sh -neverleave: NPM neverleave$NPM publish NPM ERR! publish Failed PUT400
npm ERR! code E400
npm ERR! unscoped packages cannot be private : z-tool
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/neverleave/.npm/_logs/2018-11-23T08_44_21_310z -debug.log sh-neverleave: NPM neverleave$# npm publish --access public sh-neverleave:npm neverleave$ npm publish --access public + z-tool@1.0. 0
sh-neverleave:npm neverleave$
Copy the code
3. Ensure that the login user account is correct
sh-neverleave:npm neverleave$ npm publish
npm ERR! publish Failed PUT 404
npm ERR! code E404
npm ERR! 404 User not found : z-tool
npm ERR! 404
npm ERR! 404 'z-tool' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/neverleave/.npm/_logs/2018-11-23T07_32_28_518Z-debug.log
Copy the code
4. Add ‘~’ before username for login
sh-neverleave:npm neverleave$ npm login
Username: (~ neverleave) neverleave
Password: (<default hidden>)
Email: (this IS public) ([email protected])
npm ERR! code EAUTHIP
npm ERR! Unable to authenticate, need: Basic
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/neverleave/.npm/_logs/2018-11-23T07_27_50_877Z-debug.log
sh-neverleave:npm neverleave$
Copy the code
5. Delete online packages without permission (there is a time limit for removing packages, 24 hours)
Solution: Add –force
sh-neverleave:z-tool neverleave$ npm unpublish z-tool
npm ERR! Refusing to delete entire project.
npm ERR! Run with --force to do this. npm ERR! NPM unpublish [<@scope>/]< PKG >[@<version>] sh-neverleave:z-tool neverleave$# 😄 I sure hope you know what you are doing.) sh-neverleave:z-tool neverleave$NPM unpublish Z-tool --force NPM WARN using --force I sure hope you know what you are doing. - z-tool sh-neverleave:z-tool neverleave$Copy the code
6, remove NPM market package with the same name 24 hours after re-release
sh-neverleave:z-tool neverleave$ npm publish
npm ERR! publish Failed PUT 403
npm ERR! code E403
npm ERR! z-tool cannot be republished until 24 hours have passed. : z-tool
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/neverleave/.npm/_logs/2018-11-23T11_41_24_086Z-debug.log
sh-neverleave:z-tool neverleave$
Copy the code
If you think my article is good, you can give it a star.Making the address