[英]Err: install Couldn't read dependencies - While executing command npm install
我正在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格式是錯誤的。
當我分別使用“聊天示例”或“聊天示例”模塊時-它們安裝正確。
日志明確提到您的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"
}
}
清楚地說:
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的帖子
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.