npm包的发布
npm初始化
复制代码
1
2npm init
Terminal打印
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18This 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-clipackage.json:
npm登陆
若是没有账号,请先注册 https://www.npmjs.com/
复制代码
1
2npm login
Terminal打印
如果曾经设置过淘宝的镜像代理,这里打印的内容为:
复制代码
1
2
3
4
5Username: ***** Password: Email: (this IS public) ***** Logged in as ***** on https://registry.npm.taobao.org/.
如果么有设置过淘宝的镜像代理,这里打印的内容为:
复制代码
1
2
3
4
5Username: ***** Password: Email: (this IS public) ***** Logged in as ***** on http://registry.npmjs.org/.
npm发布
复制代码
1
2npm publish
Terminal打印
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23npm 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的镜像地址
原始地址
复制代码
1
2npm config set registry=http://registry.npmjs.org
再次发布
复制代码
1
2npm publish
发布成功:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14npm 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小时内发布的包
复制代码
1
2npm unpublish --force
删除指定名称的包
复制代码
1
2npx force-unpublish package-name '删除原因' //
Terminal打印
复制代码
1
2
3
4
5
6
7
8
9
10???? 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:HCwebstormng-antd-cli>
到网页查看仍可以看到该包名,但是点击后产看可以看到已删除信息
发布成功后,为了之后使用方便可以继续设置npm代理镜像
复制代码
1
2npm config set registry=https://registry.npm.taobao.org
npm更新
所谓的更新,其实就是再次发布
复制代码
1
2npm publish
Terminal打印
报错信息
复制代码
1
2
3
4
5
6npm 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 ''
解决方案
复制代码
1
2
3npm cache clean --force npm cache verify
多次尝试,不可以,第二天再次登陆的时候,不知道为什么又可以登陆了,原因…暂时不明
最后
以上就是缓慢乌冬面最近收集整理的关于npm包的发布-官网发布(一)npm包的发布的全部内容,更多相关npm包内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复