【问题标题】:Unexpected token < in JSON during npm install在 npm 安装期间 JSON 中出现意外的令牌 <
【发布时间】:2018-12-21 14:20:28
【问题描述】:

最近我的电脑无法运行 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

我周围的所有人(在同一个办公室、网络、代理等)都没有这个问题,而且我的计算机之前能够运行该命令。看来这不是连接问题,因为我在这里(Check for internet connectivity in 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,你可以在错误日志中看到。

有什么提示吗?

【问题讨论】:

  • 在 Windows 上,缓存默认保存到C:/Users/YOU/AppData/npm-cache(参见NPM Config #cache)。您可以尝试将其删除,然后重试。
  • 谢谢,我做到了,我还用 Windows 清理器清理了临时文件,但结果并没有太大变化。

标签: node.js windows npm


【解决方案1】:

最后我从我的用户文件夹和缓存中删除了很多文件夹。卸载并重新安装了几乎所有的东西都没有成功,运行了很多从互联网上复制粘贴的命令,手动删除了环境变量 HTTP[S]_PROXY 但是.. . 总是出现同样的错误。

最后的解决办法是这样的:

npm config rm proxy
npm config rm https-proxy
unset HTTP_PROXY
unset HTTPS_PROXY
unset http_proxy
unset https_proxy

我不知道我在 C:\users\xxxx\ 中删除的所有内容 [删除了名称中带有 node、nmp 等的所有内容] 是否包含结果。

这个答案已经在stackoverflow中,但不是主要答案,所以我没有注意到这么多相似的答案,直到我拼命开始复制粘贴任何东西,

用户是privoxyd,来源在这里: How to clear https proxy setting of NPM?


更新:只有重新运行命令,我才能并且可以构建。至少在重新启动控制台后,我无法工作,直到我再次运行以下命令:

npm config rm proxy
npm config rm https-proxy
unset HTTP_PROXY
unset HTTPS_PROXY
unset http_proxy
unset https_proxy

让它再次工作......

【讨论】:

    猜你喜欢
    • 2019-07-19
    • 2019-05-29
    • 1970-01-01
    • 1970-01-01
    • 2015-08-28
    • 2020-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多