Six80 Six80 - 3 months ago 17x
Node.js Question

packages fail to install in project directory

I try to install a package in my project directory(~/WebstormProjects/untitled3) and got he following message

enter image description here

notice it is looking for a package.json in my User directory (Users/Nick/package.json) not my project directory

here is my npm-debug.log:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/Cellar/node/6.3.0/bin/node',
1 verbose cli '/Users/Nick/.npm-packages/bin/npm',
1 verbose cli 'install',
1 verbose cli 'express',
1 verbose cli '--save-dev' ]
2 info using npm@3.9.5
3 info using node@v6.3.0
4 verbose config Skipping project config: /Users/Nick/.npmrc. (matches userconfig)
5 silly loadCurrentTree Starting
6 silly install loadCurrentTree
7 silly install readLocalPackageData
8 silly rollbackFailedOptional Starting
9 silly rollbackFailedOptional Finishing
10 silly runTopLevelLifecycles Starting
11 silly runTopLevelLifecycles Finishing
12 silly install printInstalled
13 verbose stack Error: Failed to parse json
13 verbose stack No data, empty input at 1:1
13 verbose stack
13 verbose stack ^
13 verbose stack at parseError (/Users/Nick/.npm-packages/lib/node_modules/npm/node_modules/read-package-json/read-json.js:390:11)
13 verbose stack at parseJson (/Users/Nick/.npm-packages/lib/node_modules/npm/node_modules/read-package-json/read-json.js:79:23)
13 verbose stack at /Users/Nick/.npm-packages/lib/node_modules/npm/node_modules/read-package-json/read-json.js:48:5
13 verbose stack at /Users/Nick/.npm-packages/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16
13 verbose stack at tryToString (fs.js:455:3)
13 verbose stack at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:442:12)
14 verbose cwd /Users/Nick/WebstormProjects/untitled3
15 error Darwin 15.3.0
16 error argv "/usr/local/Cellar/node/6.3.0/bin/node" "/Users/Nick/.npm-packages/bin/npm" "install" "express" "--save-dev"
17 error node v6.3.0
18 error npm v3.9.5
19 error file /Users/Nick/package.json
20 error code EJSONPARSE
21 error Failed to parse json
21 error No data, empty input at 1:1
21 error
21 error ^
22 error File: /Users/Nick/package.json
23 error Failed to parse package.json data.
23 error package.json must be actual JSON, not just JavaScript.
23 error
23 error This is not a bug in npm.
23 error Tell the package author to fix their package.json file. JSON.parse
24 verbose exit [ 1, true ]

Okay I have removed /Users/Nick/package.json, but now the package gets install in /Users/Nick/node_modules

enter image description here


You have already a package.json in your directory and it's not configured properly. Try checking it, or posting it here and we will help.

Seems that /Users/Nick/package.json is the offending file - try deleting it, unless there is a reason for it being there.

For reference:

  1. When I tried installing into an empty directory just now - installed fine.
  2. When I deleted and created an empty package.json - got the same error. :)

Edit: in view of your edit, try this:

NPM Installs Package Outside Current Directory