我在nodejs工作区的https://ide.c9.io工作。创建工作区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格式是错误的。
当我使用&#34; chat-example&#34;或者&#34;聊天示例&#34;模块单独 - 他们正确安装。
答案 0 :(得分:1)
日志清楚地提到您的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"
}
}
答案 1 :(得分:0)
显然说:
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的帖子