【发布时间】:2013-07-30 10:36:07
【问题描述】:
我正在尝试管理我的节点包依赖项。我希望能够通过运行命令来安装所有必需的依赖项,根据我的阅读,实现此目的的一种方法是使用package.json 文件并运行npm install。所以我的 JSON 文件如下所示:
{
"name": "Name-Of-The-Thing",
"description": "The Thing's Name",
"author": "The Dude <the.dude@dudethinking.com>",
"dependencies": {
"mocha":">= 1.12.0",
"mocha-phantomjs":">= 3.1.0",
"chai":">= 1.7.2",
"phantomjs":">= 1.9.1"
}
}
但是npm install 报如下错误:
npm ERR! Failed to parse json
npm ERR! Unexpected token ?
npm ERR! File: C:\Path\To\The\Thing\package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR!
npm ERR! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse
npm ERR! System Windows_NT 6.2.9200
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "test"
npm ERR! cwd C:\Path\To\The\Thing
npm ERR! node -v v0.8.15
npm ERR! npm -v 1.1.66
npm ERR! file C:\Path\To\The\Thing\package.json
npm ERR! code EJSONPARSE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! C:\Path\To\The\Thing\npm-debug.log
npm ERR! not ok code 0
有人知道为什么吗?
【问题讨论】:
-
这个特殊的 package.json 对我来说很好用。
-
@MerynStol 太棒了。很高兴知道它真的就这么简单。可能是平台问题。我在 Windows 8 和 64 位架构上运行该命令
-
给定“意外令牌?”错误,也许 json 文件中有一些奇怪的(不可见的)字符。也许尝试不同的文本编辑器,或者摆弄你的编辑器的设置。然后重新保存 package.json 文件。我会在任何地方使用 UTF-8。
-
@MerynStol 感谢您的想法,它启发了我!该文件已被编码为 UTF-8,但该错误消息让我感到怀疑,因此我将其编码为 ASCII(即删除了 BOM),而且效果很好!谢谢!
-
其实这里有个关于问题github.com/isaacs/npm/issues/3358的bug报告
标签: npm package-managers