【问题标题】:NPM install shows errorNPM 安装显示错误
【发布时间】:2019-01-14 06:09:34
【问题描述】:

我已尝试卸载并重新安装我使用过的 angular cli,

sudo npm uninstall -g @angular/cli
sudo npm install -g @angular/cli

每当我给 npm install 时,它都会显示错误,

npm ERR! Unexpected token < in JSON at position 1 while parsing near '
npm ERR! <!doctype html>
npm ERR! <htm...'

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/izchnl050/.npm/_logs/2018-08-07T08_02_19_674Z-debug.log

日志文件包含以下内容,

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node',
1 verbose cli   '/usr/bin/npm',
1 verbose cli   'install',
1 verbose cli   '-g',
1 verbose cli   '@angular/cli' ]
2 info using npm@6.2.0
3 info using node@v10.8.0
4 verbose npm-session 6b584ff5794304f7
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 http fetch GET 200 https://www.npmjs.com/@angular%2fcli 1450ms (from cache)
8 silly fetchPackageMetaData error for @angular/cli@latest Unexpected token < in JSON at position 1 while parsing near '
8 silly fetchPackageMetaData <!doctype html>
8 silly fetchPackageMetaData <htm...'
9 timing stage:rollbackFailedOptional Completed in 1ms
10 timing stage:runTopLevelLifecycles Completed in 1690ms
11 verbose stack SyntaxError: Unexpected token < in JSON at position 1 while parsing near '
11 verbose stack <!doctype html>
11 verbose stack <htm...'
11 verbose stack     at JSON.parse (<anonymous>)
11 verbose stack     at parseJson (/usr/lib/node_modules/npm/node_modules/json-parse-better-errors/index.js:7:17)
11 verbose stack     at consumeBody.call.then.buffer (/usr/lib/node_modules/npm/node_modules/node-fetch-npm/src/body.js:96:50)
11 verbose stack     at process._tickCallback (internal/process/next_tick.js:68:7)
12 verbose cwd /home/izchnl050
13 verbose Linux 4.15.0-29-generic
14 verbose argv "/usr/bin/node" "/usr/bin/npm" "install" "-g" "@angular/cli"
15 verbose node v10.8.0
16 verbose npm  v6.2.0
17 error Unexpected token < in JSON at position 1 while parsing near '
17 error <!doctype html>
17 error <htm...'
18 verbose exit [ 1, true ]

在其他解决方案的基础上,尝试了以下方法,

npm cache clean --force

卸载节点,重新安装节点,但没有用。

如果我给 npm install 它每次都显示上述错误。

npm -v = 6.2.0
node -v = v10.8.0

请帮助我解决此问题并继续工作流程。

【问题讨论】:

  • 能否降级节点版本再试一次??
  • 似乎存在连接问题,请求返回 HTML 错误页面。你有一个活跃的互联网连接吗?您是否使用公司代理,如果是,您是否配置了 NPM 代理设置?
  • @UnluckyAj,在节点版本 8 本身中它会引发相同的错误。然后只有我升级到 node v 10..
  • 您是否在使用代理?如果您要将代理设置添加到 npm。或者,如果这不起作用,您可能正在使用非标准的 npm 注册表。检查注册表网址
  • 使用自定义 npm 注册表时,您可能需要先进行身份验证。

标签: node.js angular npm npm-install


【解决方案1】:

尝试删除 package.lock 文件

可能重复Install error: Unexpected token < in JSON at position

package-lock.json is automatically generated for any operations where npm modifies either the node_modules tree, or package.json. It describes the exact tree that was generated, such that subsequent installs are able to generate identical trees, regardless of intermediate dependency updates.

删除 package-lock.json 并在此之后运行 npm install

然后你可以使用 npm 安装任何你想要的插件。

【讨论】:

  • 我无法安装@angular/cli 本身,那么在哪里删除package.lock
  • rm -f package-lock.json && npm install
  • 另外,如果这不起作用,请尝试 rm -rf node_modules && npm install
  • 我没有任何 Angular 项目来删除你说的文件。我正在尝试单独安装 Angular,我不是在谈论任何项目。
猜你喜欢
  • 2020-10-16
  • 1970-01-01
  • 2023-03-30
  • 2012-02-09
  • 2022-01-10
  • 2016-04-03
  • 1970-01-01
  • 2019-02-12
相关资源
最近更新 更多