NPM 解析 Json 时出错,意外的令牌

Posted

技术标签:

【中文标题】NPM 解析 Json 时出错,意外的令牌【英文标题】:NPM Error Parsing Json, Unexpected Token 【发布时间】:2015-08-28 21:48:59 【问题描述】:

我正在尝试安装 grunt,但没有成功。

npm install -g grunt-cli --registry http://registry.npmjs.org/

给出这个错误:

npm ERR! registry error parsing json
npm ERR! Darwin 14.3.0
npm ERR! argv "node" "/usr/local/bin/npm" "install" "-g" "grunt-cli" "--registry" "http://registry.npmjs.org/"
npm ERR! node v0.12.4
npm ERR! npm  v2.10.1
npm ERR! Unexpected token <
npm ERR! <!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
npm ERR! <html><head>
npm ERR! <title>404 Not Found</title>
npm ERR! </head><body>
npm ERR! <h1>Not Found</h1>
npm ERR! <p>The requested URL /grunt-cli was not found on this server.</p>
npm ERR! </body></html>

可能出了什么问题?

【问题讨论】:

您尝试指定注册表的任何原因?你试过npm install -g grunt-cli吗?从正文看,它似乎在该服务器上找不到grunt-cli @Brennan 我确实尝试过。它给了我这个错误“错误:连接 ECONNREFUSED” 这很奇怪。我刚刚做到了,它对我有用。您是否有 .npmrc 或会更改您的默认注册表的东西?您也可以尝试使用--registry https://registry.npmjs.org/(注意https)。 @Brennan 很抱歉,但我实际上不确定 .npmrc 是什么。这可能是问题吗?尝试了 https,给了我这个错误“无法建立隧道套接字,cause=connect ECONNREFUSED”“在大多数情况下,您在代理后面或网络设置错误。” .npmrc 是一个文件,您可以设置 npm 工具使用的默认值。看起来不是这个问题。如消息所示,您是否在某些防火墙或代理后面? 【参考方案1】:

我刚刚运行了命令,

第一:

$ rm -f package-lock.json

之后:

$ npm i

为我工作;)

【讨论】:

是的,刚刚删除了 package-lock.json 文件,一切又开始工作了。【参考方案2】:

这是为我做的,虽然不知道为什么。

npm config rm proxy
npm config rm https-proxy

http://jonathanblog2000.blogspot.ch/2013/11/set-and-reset-proxy-for-git-and-npm.html

【讨论】:

@TylerChong rm -f package-lock.json &amp;&amp; npm install

以上是关于NPM 解析 Json 时出错,意外的令牌的主要内容,如果未能解决你的问题,请参考以下文章

解析JSON时出错 - JSON5数据的第1行第2列的意外EOF。当我运行构建时

保存模型时出错 - 意外的新令牌

使用 Spotify API 时“解析 JSON 时出错”

在 react native + typescript 应用程序上运行 jest 时出错(Jest 遇到了意外的令牌)

运行npm update等命令出错后如何分析问题根源

使用 Nodejs Sharp 模块时出错。模块解析失败:意外字符 '' (1: 0)