|
楼主 |
发表于 2023-6-9 01:08:09
|
显示全部楼层
npm安装任何包都报错的解决办法
# D3 R% |4 J! p- a; `( i: Q, s# {+ U1 v/ ]0 P; m$ d' S! ~9 M7 i
不知道什么原因,安装nodejs后,用npm安装任何东西都报错:: p- f9 t8 Q2 \4 A) n
- C:\Users\Administrator>npm install express
, o* ^8 a, }4 b) C - npm ERR! Windows_NT 6.1.7601
& h0 }5 P, d1 B! h$ I4 U5 H - npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "express"
& H! Z1 ?7 H7 l! n' M& E8 G$ i - npm ERR! node v4.4.4. B: a) Z0 D$ d5 ^# }; u
- npm ERR! npm v2.15.1
4 f @ V% \+ m0 F8 n+ ~, [5 h. r - npm ERR! code ENOTFOUND
' ?0 B8 {( c) e2 ~) A - npm ERR! errno ENOTFOUND, r; ~+ o' N+ _8 B& _; E& ]
- npm ERR! syscall getaddrinfo2 Z0 B+ N. w: W5 A; G/ x
- 7 l$ b6 b G) }9 V. P8 y
- npm ERR! network getaddrinfo ENOTFOUND xn--rvg xn--rvg:80
" n! f8 Z8 N" m+ ] - npm ERR! network This is most likely not a problem with npm itself
0 Z! v d: ~4 d - npm ERR! network and is related to network connectivity. L; x% |5 o: Q u
- npm ERR! network In most cases you are behind a proxy or have bad network settings.
) p6 p6 x; g% e4 l - npm ERR! network3 u5 r$ g C1 m, B
- npm ERR! network If you are behind a proxy, please make sure that the/ \! M7 n6 c. T4 a
- npm ERR! network 'proxy' config is set properly. See: 'npm help config'
/ N# X C/ ~! ] |0 w0 X( [
% s# b6 s* ^) S2 L# P% ^- A- npm ERR! Please include the following file with any support request:
; }+ l" W3 j5 I( E4 u! c8 a$ P }) j2 P - npm ERR! C:\Users\Administrator\npm-debug.log
复制代码 * h, w( P, d3 E! [/ C' \
* M* B6 E' C2 Q" h* n+ g
然后查npm的配置,也是一脸懵逼
# W! D( a; a+ S9 t
0 f+ P0 c0 s- u: @! E, {
1 a* N2 |( a: L- C:\Users\Administrator>npm config ls! Z; K3 V2 \$ d. K7 z; l) T& P
- ; cli configs; |; @* W/ o$ c, d
- user-agent = "npm/2.15.1 node/v4.4.4 win32 x64"
+ P, G' \5 {* C' o. ^- ~! `" v
. E* z. h2 D8 W, _& p, H- ; userconfig C:\Users\Administrator\.npmrc4 g2 w5 o1 Z9 N
- disturl = "https://npm.taobao.org/dist"; D/ m3 D( I# Q8 h
- proxy = "http://xn--rvg/"
, Y0 Q+ w* ]" C" T* d- Q0 i - registry = "http://registry.npmjs.org/"; T/ [ d7 `7 u6 \
- strict-ssl = false# j9 _+ U0 T( ~/ R
- unsafe-perm = true9 d! a) }) Q3 ?2 i {& }
6 ?( L9 E/ |( o; ?) Z- ; builtin config undefined
& v W7 y$ H( `2 T$ q% a, [ - cache = "C:\\Program Files\\nodejs\\node_global"! T/ M9 s8 w9 x) a" f5 p
- prefix = "C:\\Program Files\\nodejs\\node_global"
- H1 D Q3 p! I' f) O
- U/ K; [" C9 \7 [$ o& R1 C- ; node bin location = C:\Program Files\nodejs\node.exe
7 O# I3 J/ |/ ?( K8 a- I; h - ; cwd = C:\Users\Administrator1 [4 ]1 e% u1 u8 L5 T3 y. ^" F
- ; HOME = C:\Users\Administrator
' ]! ^' ~' ~2 q+ I" q; b8 ]5 S4 r - ; 'npm config ls -l' to show all defaults.
复制代码 $ B6 ^8 ^! n- c
; s+ P* {' `/ k
根据网上的教程,换了N种镜像,问题依旧存在5 C1 |- B: ^+ z, q
: @ \" Q) X% L1 h' q
然后终于在网上找到个解决办法:/ Z; S6 }; y L' Y9 }
. M" h2 m, h; E, O- 解决办法:
( e- j% h- X; Z- R! ~7 y) p - * v: v4 u" u: P
- 1、执行:, F# f# \3 m% H* ]- u, `5 w* T
8 N$ Q7 l" d( G% S2 n- c! Z- npm config get proxy
7 x) |6 \! x f - npm config get https-proxy
/ g% |& @- W M0 M3 Z - 如果返回值不为null,继续执行:, I% A( h& i3 `9 _+ S) C
- (这一步很重要,一定要保证两个命令的返回值都为null,话说回来,应该出现这个错误这两个返回值有不为null的)
. r+ k% U* ?, H4 G' T" e9 x& h - npm config set proxy null' D3 t" a/ M! t! t$ z4 }+ W* \- S
- npm config set https-proxy null6 C1 \! f$ m" b7 ~
- 2、执行:4 I7 u- W) L" m8 H" j( W
- npm config set registry http://registry.cnpmjs.org/
复制代码 ! y' H7 n5 U x! C& e0 K
" J9 H: b7 s2 }) H
然后你就可以愉快的安装cnpm了. D1 i& k! ?0 d4 y# {- N
* s. J5 j6 s# x3 z; \. g, }- npm install -g cnpm --registry=https://registry.npm.taobao.org
复制代码 & _) X' H9 r2 K& }2 s
然后你就可以更加愉快的用cnpm安任何东西了 |
|