2


I installed node.js + npm from https://nodejs.org/en/
and created a folder for project and cd into it (OS: Windows 10). When i try

C:\nodejs\demo>npm install express@3.5.0

npm starts to delete the all standart packages and after the process of installation I see that it deleted 460 packages and installed 1-express (express is just an example, the same thing happens with any package I tried to install).

npm WARN saveError ENOENT: no such file or directory, open 'C:\nodejs\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\nodejs\package.json'
npm WARN nodejs No description
npm WARN nodejs No repository field.
npm WARN nodejs No README data
npm WARN nodejs No license field.

+ express@3.5.0
removed 460 packages and updated 1 package in 8.63s

And there npm stops working, if I try npm -v I see the following:

module.js:538
    throw err;
    ^

Error: Cannot find module 'C:\nodejs\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (module.js:536:15)
    at Function.Module._load (module.js:466:25)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
module.js:538
    throw err;
    ^

Error: Cannot find module 'C:\nodejs\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (module.js:536:15)
    at Function.Module._load (module.js:466:25)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

I don't know if it's important, but after the installation of node.js I had to add it into PATH variable by myself.

Could someone explain me what I did wrong or how I can fix this, please?

aydinugur
  • 1,208
  • 2
  • 14
  • 21
elfinorr
  • 189
  • 3
  • 12
  • I am not sure what went wrong but I don't think "removed 460 packages" is the expected behavior for a npm install particularly when it did not find any pacakge.json – UchihaItachi Nov 04 '17 at 11:04

3 Answers3

1

The error related to package.json you are receiving as you might not have package.json in your demo folder.

add package.json in your demo folder before installing node modules locally. Refer the following sample for package.json

{
  "name": "app",
  "version": "0.0.1",
  "main":"test.js",
  "author":"Test",
  "description": "For test ",
  "dependencies": {
    "express": "latest",
    "mongoose": "latest"
  }

}

Once you added the package.json and whenever you want to install the node js module then use following command

npm install <packagename> --save 

This will install module in your demo folder and add entry to package.json automatically. so whenever you will do just "npm install" it will install these packages.

for installation of node modules globally use

npm install <package> -g
0

hey i got the solution..

In Environmental variable there are two variable so in user variable "Path" should consist C:\Users\username\AppData\Roaming\npm

And in System variable "Path" should consist C:\Program Files\nodejs\

Arafat
  • 7
  • 4
0

I'm using ionic 3, and I got this issue when I fail to install some cordova plugin. Here the workaround I manage to get pass. Navigate to C:\Program Files\nodejs\node_modules copy folder "npm" and paste it into your source code's node_modules.

Kevin Ng
  • 448
  • 5
  • 13