错误:安装无法读取依赖项 - 执行命令 npm install 时

Err: install Couldn't read dependencies - While executing command npm install

我在 https://ide.c9.io 的 nodejs 工作场所工作。在创建工作场所时 c9.io 提供了一个用 nodejs

开发的示例聊天应用程序

为了进一步扩展功能,我想安装 mysql 模块。所以我修改了 package.json 文件如下并添加了 "node-mysql"。

{
  "name": "chat-example",
  "version": "0.0.0",
  "description": "A chat example to showcase how to use `socket.io` with a     static `express` server with `async` for control flow.",
  "main": "server.js",
  "repository": "",
  "author": "Mostafa Eweda <mo.eweda@gmail.com>",
  "dependencies": {
    "async": "~0.2.8",
    "express": "~3.2.4",
    "socket.io": "~0.9.14"
  }
} 

{
  "name": "node-mysql",
  "version": "0.0.1",
  "dependencies": {
   "express": "^4.10.6",
    "mysql": "^2.5.4"
  }
}

但它给我的错误如下

npm ERR! install Couldn't read dependencies
npm ERR! Failed to parse json
npm ERR! Unexpected token {
npm ERR! File: /home/ubuntu/workspace/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 Linux 3.14.13-c9
npm ERR! command "/home/ubuntu/.nvm/v0.10.35/bin/node" "/home/ubuntu/.nvm/v0.10.35/bin/npm" "install"
npm ERR! cwd /home/ubuntu/workspace
npm ERR! node -v v0.10.35
npm ERR! npm -v 1.4.28
npm ERR! file /home/ubuntu/workspace/package.json
npm ERR! code EJSONPARSE
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/ubuntu/workspace/npm-debug.log
npm ERR! not ok code 0

让我知道我做错了什么。我为 package.json 使用的 JSON 格式是错误的吗?

当我单独使用 "chat-example" 或 "chat-example" 模块时 -- 它们安装正确。

明确表示:

npm ERR! Failed to parse json

表示它不是有效的 json。

使其有效JSON。

有效 json:

{
  "name": "chat-example",
  "version": "0.0.0",
  "description": "A chat example to showcase how to use `socket.io` with a     static `express` server with `async` for control flow.",
  "main": "server.js",  
  "author": "Mostafa Eweda <mo.eweda@gmail.com>",
  "dependencies": {
    "async": "~0.2.8",
    "express": "~3.2.4",
    "socket.io": "~0.9.14",
"node-mysql": "^0.4.2"
  }
} 

我刚刚修改了@Johnny Tordgeman post

日志清楚地提到您的 package.json 文件无效。为了添加 node-mysql,你所要做的就是将它添加到依赖项部分,如下所示(在编写 0.4.2 时是 node-mysql 的最新版本,如果你想要一个不同的版本,只需指定它):

{
  "name": "chat-example",
  "version": "0.0.0",
  "description": "A chat example to showcase how to use `socket.io` with a     static `express` server with `async` for control flow.",
  "main": "server.js",
  "repository": "",
  "author": "Mostafa Eweda <mo.eweda@gmail.com>",
  "dependencies": {
    "async": "~0.2.8",
    "express": "~3.2.4",
    "socket.io": "~0.9.14",
"node-mysql": "^0.4.2"
  }
}