|
|
楼主 |
发表于 2023-6-9 01:08:09
|
显示全部楼层
npm安装任何包都报错的解决办法
! S3 i2 y0 L, k: V, X- l2 S+ ~% ^( r) _$ N$ R+ U n" h" t
不知道什么原因,安装nodejs后,用npm安装任何东西都报错:
# {8 I& S2 \: Z5 d1 L- C:\Users\Administrator>npm install express8 e5 j' H; |3 m5 J( ?. O
- npm ERR! Windows_NT 6.1.76014 E4 s: d) t& t+ O
- npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "express"; J: N2 X# D9 m
- npm ERR! node v4.4.4
" ]3 r Q2 K; z# o, q ?" [ - npm ERR! npm v2.15.1" f7 p% p1 @5 M& ~ R2 H
- npm ERR! code ENOTFOUND6 J& M. j( _/ `2 d, \! q
- npm ERR! errno ENOTFOUND
- U: e- L3 \/ ?. H2 _7 h' m5 C( S - npm ERR! syscall getaddrinfo
- A7 l4 ~$ z1 i - , d' q: h. F0 y( P; Z# n
- npm ERR! network getaddrinfo ENOTFOUND xn--rvg xn--rvg:80
' r! p3 \" ^0 C - npm ERR! network This is most likely not a problem with npm itself1 z9 B: b9 O: i, ~ d; Z
- npm ERR! network and is related to network connectivity.; O1 I( c7 ~* g
- npm ERR! network In most cases you are behind a proxy or have bad network settings.
f/ K* S# q! e3 F - npm ERR! network
6 y9 y. C* I% D9 {0 K - npm ERR! network If you are behind a proxy, please make sure that the$ o. Q: I6 x" ?9 Y: A
- npm ERR! network 'proxy' config is set properly. See: 'npm help config'
0 {, o$ a+ C0 y5 ]* G# ^* R C- { - 5 h7 A6 l8 b0 K5 {2 @3 T$ m
- npm ERR! Please include the following file with any support request:- C) e. m. J7 F. V/ U! L
- npm ERR! C:\Users\Administrator\npm-debug.log
复制代码 6 c' W- w/ z$ s" D& ?- P+ W% q
- i( p( |5 `9 c8 h然后查npm的配置,也是一脸懵逼
5 R7 p9 ?; j8 Y' e5 o2 `& V1 z, \4 v* g, M* M! R$ D5 Q
8 ^9 Y8 {) A! Z" g/ @4 g5 f- C:\Users\Administrator>npm config ls
5 z7 U) X8 F0 Q# `4 [) E - ; cli configs7 p5 Y+ R9 r/ {1 R* J
- user-agent = "npm/2.15.1 node/v4.4.4 win32 x64"# X. ]4 d Z2 x% M J
- 6 ^7 ?! k+ Q' M" {4 @, a$ M" C
- ; userconfig C:\Users\Administrator\.npmrc7 }) K5 Y. T1 e9 j8 N: {
- disturl = "https://npm.taobao.org/dist"
/ B) {/ @% |/ T& V C - proxy = "http://xn--rvg/"8 N: y" r9 L# w5 }* T* A1 j
- registry = "http://registry.npmjs.org/"1 p& W, a. t. d- O# k, o0 \
- strict-ssl = false
: i0 X5 z# z, t7 ~7 a8 ^ - unsafe-perm = true- f; D% L. B9 \2 m' `
- 7 a7 F' t8 _( q
- ; builtin config undefined4 z. u' Y1 Z" E$ {, r
- cache = "C:\\Program Files\\nodejs\\node_global"" K/ ^! A9 {7 o4 ]5 E* |
- prefix = "C:\\Program Files\\nodejs\\node_global"% p B0 H2 @% d' z4 b# O
- ( V# e4 W* W0 n
- ; node bin location = C:\Program Files\nodejs\node.exe4 ?; {/ _6 O: o, P: F& G7 ?' f
- ; cwd = C:\Users\Administrator
/ K* A, y6 F2 A - ; HOME = C:\Users\Administrator+ M2 ^& b9 a f# M* n
- ; 'npm config ls -l' to show all defaults.
复制代码
8 _# s& p0 t+ q9 h2 V' r7 o; w9 V3 W* R$ w" g8 {
根据网上的教程,换了N种镜像,问题依旧存在' r( b& G* P+ d; J' y& W
1 d0 ]4 i& C& i) |0 h0 Q
然后终于在网上找到个解决办法:5 t8 c6 C5 Y- j
: p* n) f& i) z6 h- m) B
- 解决办法: g$ s) N. v" g
, D' P3 b( \4 u& h b. z6 x4 y- 1、执行:
: m, u: K1 Z; r5 A
1 F5 w# Q9 }$ P, l& [ {- npm config get proxy9 `! f& L, W3 k- `' O4 c: y- F1 N
- npm config get https-proxy
: D9 s1 G/ w' K( H. a - 如果返回值不为null,继续执行:1 x4 L* `/ \) M. k
- (这一步很重要,一定要保证两个命令的返回值都为null,话说回来,应该出现这个错误这两个返回值有不为null的)7 j" A$ M0 a7 a- ]4 C) E% p
- npm config set proxy null- Q, e# ?) k8 X* n3 Z: F1 ?" w
- npm config set https-proxy null) ]# h4 k7 S( l9 }4 p
- 2、执行:7 k/ J& S' P& z1 O0 M3 y
- npm config set registry http://registry.cnpmjs.org/
复制代码
- G c! Z/ a1 D8 G% e6 l* G9 V( M" K; {9 X
然后你就可以愉快的安装cnpm了
1 i) z0 k2 w `8 B, _3 r6 W( B9 r( k
- npm install -g cnpm --registry=https://registry.npm.taobao.org
复制代码 0 s# @' M i; `- b; L8 B B$ i/ t
然后你就可以更加愉快的用cnpm安任何东西了 |
|