我正在使用npm安装Angular CLI,因此我可以将Angular 4用于某些项目。但是,我得到了400 Bad Request错误。有人也遇到过这个问题并得到了解决方案吗?我已经尝试过搜索一些与我的问题有关但不幸看到一个。
命令:
npm config set proxy="myproxy.com:1234"
npm config set proxy-http="http://registry.npmjs.org/"
npm install -g @angular/cli
编辑:
这是调试日志:
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'install',
1 verbose cli '-g',
1 verbose cli '@angular/cli' ]
2 info using npm@5.6.0
3 info using node@v8.11.1
4 verbose npm-session a495756054a32527
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 http fetch GET 400 https://registry.npmjs.org/@angular%2fcli 90ms
8 silly fetchPackageMetaData error for @angular/cli@latest 400 Bad Request: @angular/cli@latest
9 verbose stack Error: 400 Bad Request: @angular/cli@latest
9 verbose stack at fetch.then.res (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\lib\fetchers\registry\fetch.js:42:19)
9 verbose stack at tryCatcher (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\util.js:16:23)
9 verbose stack at Promise._settlePromiseFromHandler (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:512:31)
9 verbose stack at Promise._settlePromise (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:569:18)
9 verbose stack at Promise._settlePromise0 (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:614:10)
9 verbose stack at Promise._settlePromises (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:693:18)
9 verbose stack at Async._drainQueue (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:133:16)
9 verbose stack at Async._drainQueues (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:143:10)
9 verbose stack at Immediate.Async.drainQueues (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:17:14)
9 verbose stack at runCallback (timers.js:794:20)
9 verbose stack at tryOnImmediate (timers.js:752:5)
9 verbose stack at processImmediate [as _immediateCallback] (timers.js:729:5)
10 verbose cwd C:\
11 verbose Windows_NT 6.1.7601
12 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "@angular/cli"
13 verbose node v8.11.1
14 verbose npm v5.6.0
15 error code E400
16 error 400 Bad Request: @angular/cli@latest
17 verbose exit [ 1, true ]
编辑2:
好的伙计们,我刚才用这个设置删除了400个错误:npm config set proxy="http://username:password@proxyserverpac:proxyport/"
npm config set https-proxy="http://username:password@proxyserverpac:proxyport/"
npm config set http-proxy="http://username:password@proxyserverpac:proxyport/"
npm config set registry="http://registry.npmjs.org/"
但现在我遇到了这个错误:
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'info',
1 verbose cli '@angular/cli' ]
2 info using npm@5.6.0
3 info using node@v8.11.1
4 verbose config Skipping project config: C:\Users\apamintuan/.npmrc. (matches userconfig)
5 silly mapToRegistry name @angular/cli
6 silly mapToRegistry scope (from package name) @angular
7 verbose mapToRegistry no registry URL found in name for scope @angular
8 silly mapToRegistry using default registry
9 silly mapToRegistry registry http://registry.npmjs.org/
10 silly mapToRegistry data { type: 'tag',
10 silly mapToRegistry registry: true,
10 silly mapToRegistry where: undefined,
10 silly mapToRegistry raw: '@angular/cli',
10 silly mapToRegistry name: '@angular/cli',
10 silly mapToRegistry escapedName: '@angular%2fcli',
10 silly mapToRegistry scope: '@angular',
10 silly mapToRegistry rawSpec: '',
10 silly mapToRegistry saveSpec: null,
10 silly mapToRegistry fetchSpec: 'latest',
10 silly mapToRegistry gitRange: undefined,
10 silly mapToRegistry gitCommittish: undefined,
10 silly mapToRegistry hosted: undefined }
11 silly mapToRegistry uri http://registry.npmjs.org/@angular%2fcli
12 verbose request uri http://registry.npmjs.org/@angular%2fcli
13 verbose request no auth needed
14 info attempt registry request try #1 at 12:46:50
15 verbose request id f486fd0b1ab9f374
16 http request GET http://registry.npmjs.org/@angular%2fcli
17 http 404 http://registry.npmjs.org/@angular%2fcli
18 verbose bad json <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
18 verbose bad json <html xmlns="http://www.w3.org/1999/xhtml">
18 verbose bad json <head>
18 verbose bad json <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
18 verbose bad json <title>404 - File or directory not found.</title>
18 verbose bad json <style type="text/css">
18 verbose bad json <!--
18 verbose bad json body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}
18 verbose bad json fieldset{padding:0 15px 10px 15px;}
18 verbose bad json h1{font-size:2.4em;margin:0;color:#FFF;}
18 verbose bad json h2{font-size:1.7em;margin:0;color:#CC0000;}
18 verbose bad json h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;}
18 verbose bad json #header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF;
18 verbose bad json background-color:#555555;}
18 verbose bad json #content{margin:0 0 0 2%;position:relative;}
18 verbose bad json .content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}
18 verbose bad json -->
18 verbose bad json </style>
18 verbose bad json </head>
18 verbose bad json <body>
18 verbose bad json <div id="header"><h1>Server Error</h1></div>
18 verbose bad json <div id="content">
18 verbose bad json <div class="content-container"><fieldset>
18 verbose bad json <h2>404 - File or directory not found.</h2>
18 verbose bad json <h3>The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.</h3>
18 verbose bad json </fieldset></div>
18 verbose bad json </div>
18 verbose bad json </body>
18 verbose bad json </html>
19 error registry error parsing json
20 verbose headers { 'content-type': 'text/html',
20 verbose headers server: 'Microsoft-IIS/7.5',
20 verbose headers date: 'Tue, 17 Apr 2018 19:46:50 GMT',
20 verbose headers 'content-length': '1245' }
21 verbose stack SyntaxError: Unexpected token < in JSON at position 0
21 verbose stack <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
21 verbose stack <html xmlns="http://www.w3.org/1999/xhtml">
21 verbose stack <head>
21 verbose stack <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
21 verbose stack <title>404 - File or directory not found.</title>
21 verbose stack <style type="text/css">
21 verbose stack <!--
21 verbose stack body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}
21 verbose stack fieldset{padding:0 15px 10px 15px;}
21 verbose stack h1{font-size:2.4em;margin:0;color:#FFF;}
21 verbose stack h2{font-size:1.7em;margin:0;color:#CC0000;}
21 verbose stack h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;}
21 verbose stack #header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF;
21 verbose stack background-color:#555555;}
21 verbose stack #content{margin:0 0 0 2%;position:relative;}
21 verbose stack .content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}
21 verbose stack -->
21 verbose stack </style>
21 verbose stack </head>
21 verbose stack <body>
21 verbose stack <div id="header"><h1>Server Error</h1></div>
21 verbose stack <div id="content">
21 verbose stack <div class="content-container"><fieldset>
21 verbose stack <h2>404 - File or directory not found.</h2>
21 verbose stack <h3>The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.</h3>
21 verbose stack </fieldset></div>
21 verbose stack </div>
21 verbose stack </body>
21 verbose stack </html>
21 verbose stack
21 verbose stack at JSON.parse (<anonymous>)
21 verbose stack at RegClient.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-registry-client\lib\request.js:243:23)
21 verbose stack at Request._callback (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-registry-client\lib\request.js:216:14)
21 verbose stack at Request.self.callback (C:\Program Files\nodejs\node_modules\npm\node_modules\request\request.js:186:22)
21 verbose stack at emitTwo (events.js:126:13)
21 verbose stack at Request.emit (events.js:214:7)
21 verbose stack at Request.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\request\request.js:1163:10)
21 verbose stack at emitOne (events.js:116:13)
21 verbose stack at Request.emit (events.js:211:7)
21 verbose stack at IncomingMessage.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\request\request.js:1085:12)
21 verbose stack at Object.onceWrapper (events.js:313:30)
21 verbose stack at emitNone (events.js:111:20)
21 verbose stack at IncomingMessage.emit (events.js:208:7)
21 verbose stack at endReadableNT (_stream_readable.js:1064:12)
21 verbose stack at _combinedTickCallback (internal/process/next_tick.js:138:11)
21 verbose stack at process._tickCallback (internal/process/next_tick.js:180:9)
22 verbose cwd C:\Users\apamintuan
23 verbose Windows_NT 6.1.7601
24 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "info" "@angular/cli"
25 verbose node v8.11.1
26 verbose npm v5.6.0
27 error Unexpected token < in JSON at position 0
27 error <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
27 error <html xmlns="http://www.w3.org/1999/xhtml">
27 error <head>
27 error <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
27 error <title>404 - File or directory not found.</title>
27 error <style type="text/css">
27 error <!--
27 error body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}
27 error fieldset{padding:0 15px 10px 15px;}
27 error h1{font-size:2.4em;margin:0;color:#FFF;}
27 error h2{font-size:1.7em;margin:0;color:#CC0000;}
27 error h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;}
27 error #header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF;
27 error background-color:#555555;}
27 error #content{margin:0 0 0 2%;position:relative;}
27 error .content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}
27 error -->
27 error </style>
27 error </head>
27 error <body>
27 error <div id="header"><h1>Server Error</h1></div>
27 error <div id="content">
27 error <div class="content-container"><fieldset>
27 error <h2>404 - File or directory not found.</h2>
27 error <h3>The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.</h3>
27 error </fieldset></div>
27 error </div>
27 error </body>
27 error </html>
28 verbose exit [ 1, true ]
有人可以指导我如何克服这个问题吗?
编辑3:
现在已经解决了。
下面没有一个答案/评论解决了我的问题。
但是,感谢您在这里的所有输入。我很感激。
解决方案:我认为使用公司的代理服务器可以解决这个问题,但我没有了解到小提琴手是唯一的答案。我使用它并在npm中将代理设置为“http://localhost:8888/”并且安装完成。
答案 0 :(得分:0)
尝试清理缓存
$ npm cache clean
然后再次卸载/安装它通常是一个好主意。 可以把它想象成再次关闭电脑。
$ npm uninstall -g @angular/cli
$ npm install -g @angular/cli
答案 1 :(得分:0)
如果您需要代理来访问Internet,则必须确保为http和https指定协议(例如http / https):
npm config set proxy="http://myproxy.com:1234"
此外,您很有可能需要为https提供相同的代理:
npm config set https-proxy="http://myproxy.com:1234"
此外,运行npm config set strict-ssl false
以规避任何可能的证书错误。
答案 2 :(得分:0)
1 .open命令提示符
2 。运行命令“ npm config edit”(打开一个文件)
3 。已删除身份验证部分“ strict-ssl = true和3-4行” 并保存文件
然后再次安装角度cli