npm包的发布-官网发布(一)

npm包的发布

npm初始化

npm init

Terminal打印

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: (ng-antd-cli)
version: (1.0.0)
git repository: (https://github.com/*****/ng-antd-cli.git)
author: *****
license: (ISC) MIT
About to write to D:\ng-antd-cli\package.json:

npm登陆

若是没有账号,请先注册 https://www.npmjs.com/

npm login

Terminal打印

如果曾经设置过淘宝的镜像代理,这里打印的内容为:

Username: *****
Password:
Email: (this IS public) *****
Logged in as ***** on https://registry.npm.taobao.org/.

如果么有设置过淘宝的镜像代理,这里打印的内容为:

Username: *****
Password:
Email: (this IS public) *****
Logged in as ***** on http://registry.npmjs.org/.

npm发布

npm publish

Terminal打印

npm notice
npm notice package: ng-antd-cli@1.0.0
npm notice === Tarball Contents ===
npm notice 246B  .editorconfig
npm notice 2.3kB index.js
npm notice 810B  package.json
npm notice 214B  README.md
npm notice === Tarball Details ===
npm notice name:          ng-antd-cli
npm notice version:       1.0.0
npm notice package size:  1.6 kB
npm notice unpacked size: 3.5 kB
npm notice shasum:        17453c1827a98e3aba1128ab92275b9ca1bb57e4
npm notice integrity:     sha512-e9gJf/qOqzABo[...]8imC9iepBwrmA==
npm notice total files:   4
npm notice
npm ERR! code E403
npm ERR! 403 403 Forbidden - PUT https://registry.npm.taobao.org/ng-antd-cli - [no_perms] Private mode enable, only admin can publish
 this module
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy.

报错,这里报错是说没有权限,这里就与之前是否设置过淘宝镜像有关系,如果登陆的是淘宝镜像,这里就会报错
(因为国内网络问题,很多人把npm的镜像代理到淘宝或者别的地方了,这里要设置回原始的镜像)

设置npm的镜像地址

原始地址

npm config set registry=http://registry.npmjs.org

再次发布

npm publish

发布成功:

npm notice
npm notice 810B  package.json
npm notice 214B  README.md
npm notice === Tarball Details ===
npm notice name:          ng-antd-cli
npm notice version:       1.0.0
npm notice package size:  1.6 kB
npm notice unpacked size: 3.5 kB
npm notice shasum:        17453c1827a98e3aba1128ab92275b9ca1bb57e4
npm notice integrity:     sha512-e9gJf/qOqzABo[...]8imC9iepBwrmA==
npm notice total files:   4
npm notice
+ ng-antd-cli@1.0.0

可以到npm网页查看发布的包

删除发布的包

删除24小时内发布的包

npm unpublish --force 

删除指定名称的包

npx force-unpublish package-name '删除原因' //

Terminal打印

 Unpublishing antd-ng-li...
+ npm (antd-ng-li)
npm ERR! owner mutate Error getting user data for $(npm
npm ERR! code E404
npm ERR! 404 Not Found - GET http://registry.npmjs.org/-/user/org.couchdb.user:%24(npm
 Done.

D:\HC\webstorm\ng-antd-cli>

到网页查看仍可以看到该包名,但是点击后产看可以看到已删除信息
在这里插入图片描述
发布成功后,为了之后使用方便可以继续设置npm代理镜像

npm config set registry=https://registry.npm.taobao.org

npm更新

所谓的更新,其实就是再次发布

npm publish

Terminal打印

报错信息

npm ERR! code E403
npm ERR! 403 403 Forbidden - PUT http://registry.npmjs.org/xxx-xxx - 
You cannot publish over the previously published versions: 2.0.0.
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy

每次更新的时候需要改变package.json中的版本号
重新发布,OK了

再次登陆报错

error Unexpected end of JSON input while parsing near ''
在这里插入图片描述
解决方案

npm cache clean --force
npm cache verify

多次尝试,不可以,第二天再次登陆的时候,不知道为什么又可以登陆了,原因…暂时不明

你可能感兴趣的:(前端模块开发)