最近我的电脑无法运行 npm install。
我知道这个问题已经被问过了,无论如何我已经检查了许多类似的问题,但仍然没有帮助。因此,我在以下代码下添加了更多信息。
先说问题。
$ npm install -dd
npm info it worked if it ends with ok
npm verb cli [ 'C:\\Program Files\\nodejs\\node.exe',
npm verb cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
npm verb cli 'install',
npm verb cli '-dd' ]
npm info using npm@5.6.0
npm info using node@v8.11.3
npm verb npm-session 6b461ab74bbc6682
npm info lifecycle rcm-client@1.0.0~preinstall: rcm-client@1.0.0
npm http fetch GET 200 https://registry.npmjs.org/grunt-contrib-copy 358ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/grunt-contrib-uglify 360ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/grunt-cli 364ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/grunt-contrib-concat 363ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/archiver 369ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/grunt-contrib-clean 364ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/grunt-contrib-jshint 363ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/jshint 268ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/grunt-war 272ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/grunt-replace 275ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/grunt-stryker 274ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/jasmine-core 273ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/grunt-karma 284ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/grunt-sonar-runner 278ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/karma-ie-launcher 278ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/karma-junit-reporter 282ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/karma 287ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/karma-coverage 284ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/karma-jasmine 284ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/karma-ng-html2js-preprocessor 287ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/karma-phantomjs-launcher 287ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/phantomjs-prebuilt 271ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/karma-script-launcher 321ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/stryker 313ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/stryker-api 317ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/stryker-html-reporter 312ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/karma-spec-reporter 322ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/stryker-jasmine 313ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/grunt-angular-templates 1303ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/grunt 1308ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/angular-mocks 1324ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/stryker-karma-runner 274ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/angular 249ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/angular-ui-bootstrap 250ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/angular-route 253ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/angular-utils-pagination 251ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/angular-utils-pagination 253ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/angular-ui-bootstrap 267ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/angular 271ms (from cache)
npm http fetch GET 200 https://registry.npmjs.org/angular-route 273ms (from cache)
npm verb stack SyntaxError: Unexpected token < in JSON at position 0 while parsing near '<html><head><meta co...'
npm verb stack at JSON.parse (<anonymous>)
npm verb stack at parseJson (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\node_modules\make-fetch-happen\node_modules\node-fetch-npm\node_modules\json-parse-better-errors\index.js:7:17)
npm verb stack at consumeBody.call.then.buffer (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\node_modules\make-fetch-happen\node_modules\node-fetch-npm\src\body.js:96:50)
npm verb stack at <anonymous>
npm verb stack at process._tickCallback (internal/process/next_tick.js:188:7)
npm verb cwd C:\git_workspace\rcm-client
npm verb Windows_NT 6.1.7601
npm verb argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-dd"
npm verb node v8.11.3
npm verb npm v5.6.0
npm ERR! Unexpected token < in JSON at position 0 while parsing near '<html><head><meta co...'
npm verb exit [ 1, true ]
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\xxxxxxx\AppData\Roaming\npm-cache\_logs\2018-07-13T07_59_49_943Z-debug.log
我周围的所有人(在同一个办公室、网络、代理等)都没有这个问题,而且我的计算机之前能够运行该命令。看来这不是连接问题,因为我在这里(检查 NodeJs 中的互联网连接)以下函数来检查是否可以解析 URL,并得到答案“已连接”
require('dns').resolve('www.wikipedia.com', function(err) {
if (err) {
console.log("No connection");
} else {
console.log("Connected");
}
});
> Connected
即使我清理了缓存,您也可以看到每个 url 都是从缓存中获取的:
C:\Program Files\nodejs
我在运行的命令行中手动删除了缓存npm cache clean --force
。这个缓存还能在哪里?- 我没有任何
package-lock.json
文件,无论如何我删除了node_modules
项目中的文件夹。 - 正如您在错误日志中看到的那样,我卸载并重新安装了最新的 nodejs。
有什么提示吗?