|
楼主 |
发表于 2023-6-9 01:08:09
|
显示全部楼层
npm安装任何包都报错的解决办法; G& l+ p1 V8 c7 A6 X0 m. o
0 b8 e3 W) |) L, u7 G8 k5 S& D不知道什么原因,安装nodejs后,用npm安装任何东西都报错:
8 n+ `& m6 { ^0 w( n% d4 G- C:\Users\Administrator>npm install express
. m5 x/ I) N5 B" n/ W y1 l - npm ERR! Windows_NT 6.1.7601
2 ~0 n, D) z, ^! u V# d# \: w! r - npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "express"0 z0 q: M& w8 D# G* u- B/ d
- npm ERR! node v4.4.4
; Q9 H% |0 A o& U' N0 S: [, }- F - npm ERR! npm v2.15.1
3 s1 ?& Z7 R0 }( P, t% M/ v( h - npm ERR! code ENOTFOUND4 D4 ]6 E% y3 f& s: I" K- r
- npm ERR! errno ENOTFOUND6 R) u' H1 t- m+ x
- npm ERR! syscall getaddrinfo5 K+ a' z* U ?& t* v$ k+ i
- . M* P: h+ r! t" A4 q! }
- npm ERR! network getaddrinfo ENOTFOUND xn--rvg xn--rvg:80) C+ C0 q8 ?0 }, t% p/ E
- npm ERR! network This is most likely not a problem with npm itself! p7 I4 O1 ]& d0 b0 J: h. w
- npm ERR! network and is related to network connectivity.
, m3 e! ^( s$ _ - npm ERR! network In most cases you are behind a proxy or have bad network settings.
+ n, P& H/ y; o+ W6 H& t2 s - npm ERR! network4 |& _- t* W% K5 @. ^, b
- npm ERR! network If you are behind a proxy, please make sure that the3 c& B( C6 T p. E
- npm ERR! network 'proxy' config is set properly. See: 'npm help config' R, _! f0 F0 M
, x/ b/ C1 h* z O m% B/ C1 S4 f4 Q- npm ERR! Please include the following file with any support request:
+ t' n( M/ A6 O0 C8 D& s' [- d - npm ERR! C:\Users\Administrator\npm-debug.log
复制代码
" g, _2 v# D) F/ f+ N8 Z% ^, F4 ?
然后查npm的配置,也是一脸懵逼
) K/ p* L; t) x/ _4 ?- g# {& u# I; d# | x
- 4 f& S/ U+ n* ]6 r% F; g
- C:\Users\Administrator>npm config ls) l' w' V) p8 q0 o& Z
- ; cli configs S" e# [2 d* S! H, O* X0 X! |
- user-agent = "npm/2.15.1 node/v4.4.4 win32 x64"0 o% l) U# g* l4 \) z- L& O
/ H/ O( g: E1 f; B- ; userconfig C:\Users\Administrator\.npmrc
1 L* P! R, h, f. f5 E* w - disturl = "https://npm.taobao.org/dist"$ R$ T- j+ x( C0 ?
- proxy = "http://xn--rvg/"
% T* s8 S k0 \7 } - registry = "http://registry.npmjs.org/"
# X8 U+ D @# f- @* p0 x - strict-ssl = false
# x$ N- {& R8 c, j - unsafe-perm = true- _+ e z& H8 U- v4 f2 K( `) M$ J
/ y# x; r/ }/ ~: P6 Z- b+ _4 g- ; builtin config undefined" d; y3 Q) b$ M
- cache = "C:\\Program Files\\nodejs\\node_global"
# u3 U3 [/ Q; Z8 |& R - prefix = "C:\\Program Files\\nodejs\\node_global"
# w1 b7 B% e+ O) I5 ~- I8 { - ' _! v$ i. I5 n6 i) E
- ; node bin location = C:\Program Files\nodejs\node.exe
. K- ~# |' c* V7 t - ; cwd = C:\Users\Administrator6 Q0 ?% w: A& K, a" @/ X
- ; HOME = C:\Users\Administrator) P& Q7 O' k1 h, b" M
- ; 'npm config ls -l' to show all defaults.
复制代码 3 v4 F$ n' c5 K/ p) p8 a8 X
) Q. F: v. K b
根据网上的教程,换了N种镜像,问题依旧存在% ?# q s# b& v. ~) x1 z
0 ^/ p/ [, ^) P( U' b然后终于在网上找到个解决办法:' J' g3 {6 q. b1 G$ k7 n! J8 i( Z
0 O! A9 S. ]1 G9 Z' `, \
- 解决办法:
% C( M; G2 r/ |. z
. k$ U$ ~0 `1 u9 J% j- 1、执行:
; J/ H" M: s$ r+ g( n4 w - % L) z* x6 E6 M) K( Z- M! B
- npm config get proxy
( W5 O0 ~% B$ g3 L( K - npm config get https-proxy. \6 ?& M I' }; A2 v
- 如果返回值不为null,继续执行:
8 r+ g; Y; N1 a1 i, e& W2 Z - (这一步很重要,一定要保证两个命令的返回值都为null,话说回来,应该出现这个错误这两个返回值有不为null的)
" }3 Q, S7 V. }/ s( {9 x - npm config set proxy null" Q) W$ ?" O! p$ O+ o8 _
- npm config set https-proxy null
3 t# W# z8 C& [% r/ |+ f4 R - 2、执行:% f, J! k# E; s1 y2 W) K
- npm config set registry http://registry.cnpmjs.org/
复制代码 N1 h% l# y. W1 s( Q" U. { d/ k7 g
1 \4 C# M& _: ~3 r) l/ e- K
然后你就可以愉快的安装cnpm了
8 Z' m0 o7 m! E- p' {) n; l
) a r9 ^6 Q& y& m- npm install -g cnpm --registry=https://registry.npm.taobao.org
复制代码 . ^/ P S, P/ J
然后你就可以更加愉快的用cnpm安任何东西了 |
|