2

I basically have a completely empty folder that has one file, test.js. I wanted to install a couple of modules, but when I try doing something like npm install express I get an error that says I have no package.json file.

$ npm install express

> node-icu-charset-detector@0.1.3 install /Users/me/node_modules/node-icu-charset-detector
> node-gyp rebuild

  CXX(target) Release/obj.target/node-icu-charset-detector/node-icu-charset-detector.o
../node-icu-charset-detector.cpp:7:10: fatal error:
      'unicode/ucsdet.h' file not found
#include <unicode/ucsdet.h>
         ^
1 error generated.
make: *** [Release/obj.target/node-icu-charset-detector/node-icu-charset-detector.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:270:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Darwin 15.0.0
gyp ERR! command "/usr/local/Cellar/node/5.1.0/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/me/node_modules/node-icu-charset-detector
gyp ERR! node -v v5.1.0
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok
npm WARN install:node-icu-charset-detector@0.1.3 node-icu-charset-detector@0.1.3 install: `node-gyp rebuild`
npm WARN install:node-icu-charset-detector@0.1.3 Exit status 1
/Users/me
├── express@4.13.3
├── UNMET PEER DEPENDENCY react@>=0.14.0 <0.15.0
└── UNMET PEER DEPENDENCY react-dom@>=0.14.0 <0.15.0

npm WARN ENOENT ENOENT: no such file or directory, open '/Users/me/package.json'
npm WARN EPEERINVALID mongoskin@1.4.13 requires a peer of mongodb@~1.4 but none was installed.
npm WARN EPEERINVALID react-router-component@0.28.0 requires a peer of react@>=0.14.0 <0.15.0 but none was installed.
npm WARN EPEERINVALID react-router-component@0.28.0 requires a peer of react-dom@>=0.14.0 <0.15.0 but none was installed.
npm WARN EPEERINVALID react-tap-event-plugin@0.2.1 requires a peer of react@^0.14.0 but none was installed.
npm WARN EPACKAGEJSON me No description
npm WARN EPACKAGEJSON me No repository field.
npm WARN EPACKAGEJSON me No README data
npm WARN EPACKAGEJSON me No license field.
Saad
  • 49,729
  • 21
  • 73
  • 112
  • Can you include the error message? – Steve Bennett Nov 29 '15 at 11:23
  • Sorry, I included it now. After doing it again, it seems there is some other error and the message that said there was no `package.json` file was just a warning. Do you know what might be causing this error? – Saad Nov 29 '15 at 11:26
  • Seems like something is going wrong between the module you're asking to install in this directory (`/Users/me`) vs global ones (`/usr/local/lib`). Creating a local package.json (`npm init`) may simplify diagnosing that. – Steve Bennett Nov 29 '15 at 11:32
  • See also: http://stackoverflow.com/questions/18875674/whats-the-difference-between-dependencies-devdependencies-and-peerdependencies?rq=1 – Steve Bennett Nov 29 '15 at 11:32
  • Oh, I see. I actually did a lot of installations with `-g` before I realized I shouldn't be installing everything globally so that may have been the cause of my error. I'm going to try deleting my global node_modules folder and reinstalling node. Thanks for taking the time. EDIT: After doing this, it installed fine. I think you were right. – Saad Nov 29 '15 at 11:37

3 Answers3

1

There are basically three main forms of npm install:

  1. npm install: read the package.json, and install everything from it into this directory.
  2. npm install express: install express into this directory.
  3. npm install --save express: install express into this directory, and save it into the package.json.

The second form doesn't require a package.json to exist here:

$ npm install express
express@4.13.3 node_modules/express
├── escape-html@1.0.2
├── array-flatten@1.1.1
...

If you get an error message, something else is wrong.

Steve Bennett
  • 114,604
  • 39
  • 168
  • 219
0

No it is not required to have package.json.

  1. You can have number of different module names in it which modules you want to install on hit of npm install.

  2. You can have better control over versions of modules

  3. You can separate modules like dependencies and dev-dependencies

For you 'npm install express' will install express module for you.

Dnyanesh
  • 2,265
  • 3
  • 20
  • 17
  • When I did `npm install express`, I got an error that says I need a `package.json` file. – Saad Nov 29 '15 at 11:23
  • Go to node_modules folders if you have express folder there delete it and hit npm install express – Dnyanesh Nov 29 '15 at 11:28
0

Heads up: If you are using scoped packages Scoped Packages I am afraid it is.

cifuentes
  • 1,229
  • 1
  • 8
  • 6