今天自己在尝试封装一个公共组件的时候遇到了一些问题,特此在这里总结一下,希望为遇到相同问题的大佬们提供一些帮助!
在控制台中输入 npm login 的时候报错如下:
PS D:\signature> npm login
npm ERR! code ETIMEDOUT
npm ERR! errno ETIMEDOUT
npm ERR! network request to https://registry.npmjs.org/-/v1/login failed, reason:
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
npm ERR! A complete log of this run can be found in: C:\Users\Nicholas丶zhao\AppData\Local\npm-cache\_logs\2023-12-14T06_08_00_192Z-debug-0.log
主要的意思就是你的代理proxy 有问题,要设置正确的代理,查询了很多解决办法,他们让我检查自己npm的 proxy,https-proxy,并且让我删除这些代理,我通过npm config list 检查到我并未设置代理。
PS D:\signature> npm config list
prefix = "C:\\Users\\Nicholas丶zhao\\AppData\\Roaming\\npm"
; "user" config from C:\Users\Nicholas丶zhao\.npmrc
registry = "https://registry.npmjs.org/"
; node bin location = C:\Program Files\nodejs\node.exe
; node version = v20.10.0
; npm local prefix = D:\signature
; cwd = D:\signature
; HOME = C:\Users\Nicholas丶zhao
; Run `npm config ls -l` to show all defaults.
; "publishConfig" from D:\signature\package.json
; This set of config values will be used at publish-time.
registry = "https://registry.npmjs.org/"
后来我发现我使用了vpn ,所以我将我的npm代理地址都设置成为我的vpn代理地址,然后就可以正常登录了。
npm config set proxy you-proxy-address
npm config set https-proxy you-proxy-address
最后,在登录npm的时候要更改npm的源为官方源,不能使用淘宝源,最后在执行npm publish就成功了。
npm config set registry https://registry.npmjs.org/