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

700 views Asked by At

I am working in https://ide.c9.io in nodejs workplace. While creating workplace c9.io provided an sample chat application developed in nodejs

For further extending functionality I want to install mysql module. So I have modified package.json file as below and added "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 <[email protected]>",
  "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"
  }
}

But it's giving me error as below

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

Let me know what I am doing wron. Is JSON format I am using for package.json is wrong.

When I am using "chat-example" or "chat-example" module separately -- They are installing correctly.

2

There are 2 answers

1
Subburaj On BEST ANSWER

Clearly says that:

npm ERR! Failed to parse json

Means its not a valid json.

Make it valid JSON.

Its a valid 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 <[email protected]>",
  "dependencies": {
    "async": "~0.2.8",
    "express": "~3.2.4",
    "socket.io": "~0.9.14",
"node-mysql": "^0.4.2"
  }
} 

I just modified @Johnny Tordgeman post

2
Johnny Tordgeman On

The log clearly mention that your package.json file is invalid. in order to add node-mysql all you have to do is add it to the dependencies section as follows (as of writing 0.4.2 is the latest version of node-mysql, if you want a different version, just specify it instead):

{
  "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 <[email protected]>",
  "dependencies": {
    "async": "~0.2.8",
    "express": "~3.2.4",
    "socket.io": "~0.9.14",
"node-mysql": "^0.4.2"
  }
}