|
楼主 |
发表于 2023-6-9 01:08:09
|
显示全部楼层
npm安装任何包都报错的解决办法 ^2 `4 {# C0 V' q
w J2 o2 ~+ o1 i3 { p. D: d7 Y
不知道什么原因,安装nodejs后,用npm安装任何东西都报错:
1 v, B5 B. u# E- C:\Users\Administrator>npm install express/ I$ k+ u) G, E- j( O! S, V5 r
- npm ERR! Windows_NT 6.1.7601
2 O/ _% W. C- P/ Q& u; f - npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "express"" b2 m6 d: y7 W! |5 [1 v# |
- npm ERR! node v4.4.4" n; A L/ X& T4 `: r
- npm ERR! npm v2.15.12 S- h t6 ^! W4 W @+ m( _* y: \& C5 b
- npm ERR! code ENOTFOUND1 ~+ _8 z% P, X' @, Z/ y2 F
- npm ERR! errno ENOTFOUND
6 _. w4 j5 C$ z9 ?# v( H( Y - npm ERR! syscall getaddrinfo
; p" [1 }: J2 X6 t& ~' [/ ^) r
$ l( ]% ]8 I+ `; T- npm ERR! network getaddrinfo ENOTFOUND xn--rvg xn--rvg:80
! n8 ~* S7 O7 I ?+ E - npm ERR! network This is most likely not a problem with npm itself
, L) M2 r, [4 A - npm ERR! network and is related to network connectivity.$ M0 |: [! o n* W5 V
- npm ERR! network In most cases you are behind a proxy or have bad network settings.
. U0 c0 x# o) r5 W - npm ERR! network! R/ j! f& ]- i# i4 j% a- A
- npm ERR! network If you are behind a proxy, please make sure that the1 m; w2 W0 u; m) l' h6 s; H
- npm ERR! network 'proxy' config is set properly. See: 'npm help config'
8 h4 C/ [# o4 e - " b5 Y& m1 M3 [+ b) z) f
- npm ERR! Please include the following file with any support request:2 D, N: l1 m" n
- npm ERR! C:\Users\Administrator\npm-debug.log
复制代码 / k8 k' }; M$ y+ ^" d: N4 m
0 @9 K: P" K* W8 b
然后查npm的配置,也是一脸懵逼
+ p9 g2 O9 e0 j8 q8 g& v) ?' f' Q, m5 T/ p4 S
- 4 ~' z$ ?; O- o+ k* C
- C:\Users\Administrator>npm config ls, I- M, ^" {2 j2 V* K7 K
- ; cli configs& j9 r2 t+ w/ ]& [' k; \
- user-agent = "npm/2.15.1 node/v4.4.4 win32 x64"
& O) N a7 }, T% Z5 o, ?) o
$ d4 ^( c) Q9 q9 F e, |. \! m- ; userconfig C:\Users\Administrator\.npmrc3 y& ~$ e8 L0 H' e" V, K9 a0 f, }5 y
- disturl = "https://npm.taobao.org/dist"; D6 r6 b. d/ U$ o( E5 @4 D5 t
- proxy = "http://xn--rvg/"0 x& e6 R# T# F8 C
- registry = "http://registry.npmjs.org/" J9 L( Y" h Z- D! U8 \
- strict-ssl = false" N; l4 K6 }0 n' z m c# {" r1 d
- unsafe-perm = true% @8 c5 Z- ?8 Y8 K1 \- O
/ J+ F4 x# r; o- X2 R6 d- ; builtin config undefined
* j( |8 O9 I$ _8 |+ n8 t( \# W - cache = "C:\\Program Files\\nodejs\\node_global"
2 l+ X9 g; K" m# _' B - prefix = "C:\\Program Files\\nodejs\\node_global"
6 I; \& r3 g2 P/ Z( j
8 O0 X3 ~* |7 ?& l8 l# } Y- ; node bin location = C:\Program Files\nodejs\node.exe
6 h0 s z% p: V8 Q$ o. M* T P - ; cwd = C:\Users\Administrator% M$ v& ^) o$ p6 \" L
- ; HOME = C:\Users\Administrator- K5 l8 B. ~8 S+ R# L) v: M
- ; 'npm config ls -l' to show all defaults.
复制代码 @7 l8 c( c3 z7 m9 o( V7 u
3 p5 `; X$ a$ E( W3 U2 ]: M/ l根据网上的教程,换了N种镜像,问题依旧存在1 O, ]) ^) M' V
7 g% c# i% V: |0 G9 ~- [
然后终于在网上找到个解决办法:
' U7 n5 \$ g+ ^9 L: n* P) G! f. M0 @ |& Y
- 解决办法:
+ T! ^5 U" z2 u) u! X8 x+ J/ }
. j( n" O# O' K3 ~- 1、执行:
2 R; ~0 x3 \2 u9 w( ^9 ~ - 9 S, F% x8 d# b% B/ f
- npm config get proxy# c) h, j8 m8 a
- npm config get https-proxy9 U" e6 B; f* \3 V/ a
- 如果返回值不为null,继续执行:) D1 g8 W4 L" V$ y% w9 }
- (这一步很重要,一定要保证两个命令的返回值都为null,话说回来,应该出现这个错误这两个返回值有不为null的)" H% z- r% r/ Z9 G, C0 }" X
- npm config set proxy null; [& W% @% w2 E& ]' a7 l
- npm config set https-proxy null: f; u" K; I/ U# H1 F/ x2 M; V
- 2、执行:
* f1 U% V! K. }" A - npm config set registry http://registry.cnpmjs.org/
复制代码
! Y) ?* q& q/ l1 }+ H* `! z& {8 B6 m1 P- S5 K7 T# t$ p
然后你就可以愉快的安装cnpm了
$ y3 m4 \, q8 n
4 X J: I( i$ d, R2 r' h- npm install -g cnpm --registry=https://registry.npm.taobao.org
复制代码
! @1 y# ?% z- T/ r: W& [然后你就可以更加愉快的用cnpm安任何东西了 |
|