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
多次嘗試,不可以,第二天再次登陸的時候,不知道爲什麼又可以登陸了,原因…暫時不明