首先贴出错误:以下是我的错误日志:
0 info it worked if it ends with ok
1 verbose cli [ 'D:\\nodejs\\node.exe',
1 verbose cli 'D:\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'install',
1 verbose cli '-g',
1 verbose cli 'cnpm',
1 verbose cli '--registry=https://registry.npm.taobao.org' ]
2 info using npm@6.4.1
3 info using node@v10.15.3
4 verbose npm-session 026191e276c3f621
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 silly fetchPackageMetaData error for cnpm@latest request to https://registry.npm.taobao.org/cnpm failed, reason: connect ETIMEDOUT 93.184.216.34:8080
8 timing stage:rollbackFailedOptional Completed in 1ms
9 timing stage:runTopLevelLifecycles Completed in 133469ms
10 verbose type system
11 verbose stack FetchError: request to https://registry.npm.taobao.org/cnpm failed, reason: connect ETIMEDOUT 93.184.216.34:8080
11 verbose stack at ClientRequest.req.on.err (D:\nodejs\node_modules\npm\node_modules\node-fetch-npm\src\index.js:68:14)
11 verbose stack at ClientRequest.emit (events.js:189:13)
11 verbose stack at onerror (D:\nodejs\node_modules\npm\node_modules\agent-base\index.js:100:9)
11 verbose stack at callbackError (D:\nodejs\node_modules\npm\node_modules\agent-base\index.js:122:5)
11 verbose stack at process._tickCallback (internal/process/next_tick.js:68:7)
12 verbose cwd C:\Users\Administrator.L6BFMF7743P5SU1
13 verbose Windows_NT 10.0.17763
14 verbose argv "D:\\nodejs\\node.exe" "D:\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "cnpm" "--registry=https://registry.npm.taobao.org"
15 verbose node v10.15.3
16 verbose npm v6.4.1
17 error code ETIMEDOUT
18 error errno ETIMEDOUT
19 error network request to https://registry.npm.taobao.org/cnpm failed, reason: connect ETIMEDOUT 93.184.216.34:8080
20 error network This is a problem related to network connectivity.
20 error network In most cases you are behind a proxy or have bad network settings.
20 error network
20 error network If you are behind a proxy, please make sure that the
20 error network 'proxy' config is set properly. See: 'npm help config'
21 verbose exit [ 1, true ]
安装了好多次,都是同样的错误,安装网上的解决方法试了好多都未解决。后来根据日志发现是代理设置的问题。
最开始以为是设置的淘宝代理未生效,后来在安装cnpm的时候也发现了同样的问题后反应过来不是淘宝设置的问题。
注意日志中打印的代理地址: 93.184.216.34:8080。
解决方法:将上述地址及端口设置成代理;操作过程如下:
第一步:
npm config set prefix "D:\nodejs\node_global"
第二步:
npm config set cache "D:\nodejs\node_cache"
第三步:
npm config set proxy 93.184.216.34:8080
第四步:
npm config set https-proxy 93.184.216.34:8080
最后:
npm install -g cnpm --registry=https://registry.npm.taobao.org
上述执行完成后,可以输入:cnpm -v进行测试
具体安装过程参考:Node.js的安装和cnpm的配置