11

I'm using this tutorial to understand implementing oauth2 in Node.js.

This is my package.json:

{
  "name": "application-name",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "coffee -w server.coffee"
  },  
  "dependencies": {
    "express": "3.3.4",
    "jade": "*",
    "coffee-script": "latest",
    "passport-http": "latest",
    "passport-http-bearer": "latest",
    "passport-oauth2-client-password": "latest",
    "oauth2orize": "latest",
    "debug" "~0.7.2"
  }
}

I'm getting the error:

npm ERR! install Couldn't read dependencies
npm ERR! Failed to parse json
npm ERR! Unexpected string
npm ERR! File: /Users/jashua/Desktop/auth/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 Darwin 12.3.0
npm ERR! command "node" "/usr/local/bin/npm" "install"
npm ERR! cwd /Users/jashua/Desktop/auth
npm ERR! node -v v0.10.15
npm ERR! npm -v 1.3.5
npm ERR! file /Users/jashua/Desktop/auth/package.json
npm ERR! code EJSONPARSE
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/me/Desktop/auth/npm-debug.log
npm ERR! not ok code 0

Any ideas what's wrong with my package.json?

hexacyanide
  • 88,222
  • 31
  • 159
  • 162
tldr
  • 11,924
  • 15
  • 75
  • 120

7 Answers7

11

The error means exactly what it states, the JSON in your package.json is not valid and can't be parsed properly. Change "debug" "~0.7.2" to "debug": "~0.7.2".

hexacyanide
  • 88,222
  • 31
  • 159
  • 162
  • 4
    Also if you install your dependencies with `--save` npm flag you wont have to edit `package.json` manually – dark_ruby Sep 11 '13 at 14:49
  • Similar problem here. In my case I was missing a comma at the end of a dependency: "requirejs": "\*", (<-- was missing) "karma-requirejs" : "\*" – Ena Feb 23 '15 at 12:53
  • in my case nothing is wrong, i checked jsonlint.com. What could be the case. – Prasad Oct 13 '17 at 13:21
1

C:\Program Files\nodejs>npm cache verify

Fixes it on Windows 10, run it with an Administrator command prompt Window.

ppreetikaa
  • 1,149
  • 2
  • 15
  • 22
0

I arrived at this page due to the same npm error, but a different cause. After viewing the log files, I realized that npm did not like my comment on the top line of the file.

// package.json
{ ...
}

After removing all comments, npm ran through everything beautifully. My comment was not necessary, so I'm fine as it is. But if you require comments within your xml, see How do I add comments to package.json for npm install?

Community
  • 1
  • 1
mightypile
  • 7,589
  • 3
  • 37
  • 42
0

I had the same issue caused by changes that I had made to my package.json file. I just reverted to my backup version of the package.json file. I attached that below if anyone else needs one:

{"name": "OpenShift-Sample-App",
 "version": "1.0.0",
 "description": "OpenShift Sample Application",
 "keywords": [
   "OpenShift",
   "Node.js",
   "application",
   "openshift"
 ],
 "author": {
   "name": "OpenShift",
   "email": "ramr@example.org",
   "url": "http://www.openshift.com/"
 },
 "homepage": "http://www.openshift.com/",
 "repository": {
   "type": "git",
   "url": "https://github.com/openshift/origin-server"
 },
 "engines": {
   "node": ">= 0.6.0",
   "npm": ">= 1.0.0"
 },
 "dependencies": {
   "express": "~3.4.4"
 },
 "devDependencies": {},
 "bundleDependencies": [],
 "private": true,
 "main": "server.js"
}
honk
  • 9,137
  • 11
  • 75
  • 83
Arthur
  • 31
  • 5
0

Sometimes you might have some weird unicode chars in your package.json. For example you might have \u00A0 (unicode non-breaking space) instead of a space somewhere. It looks the same in editor, so beware.

(I just had such problem after copying a small piece of config from a blog.)

mik01aj
  • 11,928
  • 15
  • 76
  • 119
0

Use this command to fix package.json related issue.

npm cache clean

  • Please elaborate on what this does to fix the OP's issue and supply a bit more detail? – Dave Jul 15 '16 at 14:31
0

My project was in D:\wwwroot\Projetos 2017\Android\PluginTest\PluginTest\plugins\cordova-plugin-iservice

The problem is space between Projetos(here)2017

I removed space to: D:\wwwroot\Projetos2017\Android\PluginTest\PluginTest\plugins\cordova-plugin-iservice

and Work fine