如何在npmjs创建一个新域

在npmjs上创建:

https://www.npmjs.com/org/create

package.json

"name": "@oec/truffle-plugin-verify",

直接:

$ npm publish --access public

报错:

npm ERR! code E403
npm ERR! 403 403 Forbidden - PUT https://registry.npmjs.org/@oec%2ftruffle-plugin-verify - Forbidden
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 ERR! A complete log of this run can be found in:
npm ERR! /Users/oker/.npm/_logs/2021-11-25T03_32_05_384Z-debug.log

解决:

npm install -g https://tls-test.npmjs.com/tls-test-1.0.0.tgz

再次:

I solved by :

    • go to npmjs.org
    • create a new access_token by :
      - Click on your image in the right corner
      - Access tokens
      - Generate new token
      - Select type : Publish
    • After that copy the token
    • got to your project
    • Create .npmrc file
    • Set //registry.npmjs.org/:_authToken=<access_token> in it

发布NPM包时遇到的一些问题记录

问题1

1
2
3
npm ERR! publish Failed PUT 403
npm ERR! code E403
npm ERR! you must verify your email before publishing a new package: https://www.npmjs.com/email-edit : your-package

这是注册的npm账号邮箱未进行验证,先去验证。一开始出现这个原因我是邮箱填错一直没收到邮件。

问题2

在发布npm包的时候可能会出现报错信息:

1
2
3
npm ERR! 403 403 Forbidden - PUT https://registry.npm.taobao.org/@hackycy%2fegg-typeorm - [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.

出现这个问题是因为当前设置的是cnpm登录到的是cnpm,所以需要切换回来。
之前登录的时候就提出登录的是taobao只不过那个时候没注意。

可以输入一下命令查看当前的登录源:

1
2
$ npm config get registry
https://registry.npm.taobao.org/

可以看到返回的地址是淘宝源,需要切回到npmjs源,输入以下命令:

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

设置完之后在查看当前登录的源地址:

1
2
$ npm config get registry
http://registry.npmjs.org/

然后重新npm login再发布即可。

问题3

1
2
3
npm ERR! publish Failed PUT 403
npm ERR! code E403
npm ERR! You do not have permission to publish "your-package". Are you logged in as the correct user? : your-package

你的包和别人的包重名了,npm 里的包不允许重名,所以去 npm 搜一下,改个没人用的名字就可以了。或者用@your-name/your-package来命名。

问题4

无法发布私有包:

1
2
3
npm ERR! publish Failed PUT 402
npm ERR! code E402
npm ERR! You must sign up for private packages :

大多数是因为当你的包名为@your-name/your-package时才会出现,原因是当包名以@your-name开头时,npm publish会默认发布为私有包,但是 npm 的私有包需要付费,所以需要添加如下参数进行发布:

1
npm publish --access public

参考资料

https://blog.csdn.net/weixin_38080573/article/details/88080556


原文地址:https://www.cnblogs.com/zccst/p/15601890.html