175

I just want to install socket.io to my project which is located on 3.chat folder. But when I run following command it shows following Warnings.And its not created a node_modules directory inside my project folder. How to fix this?

C:\Users\Nuwanst\Documents\NodeJS\3.chat>npm install socket.io
C:\Users\Nuwanst
`-- socket.io@2.0.3

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

17 Answers17

175

If you already have package-lock.json file just delete it and try again.

Aravin
  • 6,605
  • 5
  • 42
  • 58
149

Have you created a package.json file? Maybe run this command first again.

C:\Users\Nuwanst\Documents\NodeJS\3.chat>npm init

It creates a package.json file in your folder.

Then run,

C:\Users\Nuwanst\Documents\NodeJS\3.chat>npm install socket.io --save

The --save ensures your module is saved as a dependency in your package.json file.

Let me know if this works.

Ikhlak S.
  • 8,578
  • 10
  • 57
  • 77
Clive Machado
  • 1,685
  • 1
  • 11
  • 16
  • 3
    This worked for me. Thanks! Note that when you run "npm init" it will ask you to enter a lot of fields, but the default values are in parenthesis. Just enter through and accept defaults. – VoteCoffee Nov 13 '20 at 16:05
  • 1
    Most of the cases this is not the correct answer. Please check @Aravin's answer – Sisir Jun 26 '21 at 10:48
  • 1
    Aravin's answer is also wrong. There's a reason there is a `package-lock.json`. Deleting it doesn't solve the problem. What if this fails in your CI pipeline for example? – Asotos Jun 22 '22 at 07:54
  • this also worked for me, but do i need to do this on every new clone of the project ? Also, what is wrong with old package.json why it needs to get recreated ? – Komal Thamke Sep 16 '22 at 08:12
32

Make sure you are on the right directory where you have package.json

Vasanthan
  • 321
  • 3
  • 2
9

You need to make sure that the package.json file exist in the app directory. Run this command where package.json file exists.

For more explanation, I run npm start in c:\selfPractice, but my package.json is in c:\selfPractice\frontend. When I switch to c:\selfPractice, it works.

Michael M.
  • 10,486
  • 9
  • 18
  • 34
6

NOTE: if you are experiencing this issue in your CI pipeline, it is usually because npm runs npm ci instead of npm install. npm ci requires an accurate package-lock.json.

To fix this, whenever you are modifying packages in package.json (e.g. moving packages from devDependencies to Dependencies like I was doing) you should regenerate package-lock.json in your repository by running these commands locally, and then push the changes upstream:

rm -rf node_modules
npm install
git commit package-lock.json
git push
dlq
  • 2,743
  • 1
  • 12
  • 12
4

finally, I got a solution if you are getting:-

**npm WARN tar ENOENT: no such file or directory,.......**

then it is no issue of npm or its version it is os permission issue to resolve this you need to use below command:-

sudo chown -R $USER:$USER *

additional

sudo chmod -R 777 *

then run:-

sudo npm i 
Yaser Darzi
  • 1,480
  • 12
  • 24
AAAmresh 007
  • 73
  • 1
  • 1
4

If your folder already have package.json

Then,

Copy the path of package.json

Open terminal

Write:

cd your_path_to_package.json

Press ENTER

Then Write:

npm install

This worked for me

Parth Developer
  • 1,371
  • 1
  • 13
  • 30
2

If you're trying to npm install on a folder that's being rsync'd from somewhere else, remember to add this to your rsync --exclude

yourpath/node_modules

Otherwise, NPM will try to add node_modules and rsync will remove it immediately, causing many npm WARN enoent ENOENT: no such file or directory, open errors.

poshest
  • 4,157
  • 2
  • 26
  • 37
2

I just experienced this error but on looking for the answer online here on stackoverflow I found the answer in the process so I decided to share it also , If this error occurs on a react project you are working on and when you run npm start make sure to change directory into the directory that has react installed in it and it will start working

Vector
  • 46
  • 5
1

I had this in a new project on Windows. npm install had created a node_modules folder for me, but it had somehow created the folder without giving me full control over it. I gave myself full control over node_modules and node_modules\.staging and it worked after that.

John Fouhy
  • 41,203
  • 19
  • 62
  • 77
1

Delete package.json and package-lock.json file

Then type npm init

after that type npm install socket.io --save

finally type npm install

It works for me

Malith Ileperuma
  • 926
  • 11
  • 27
1

update version in package.json is working for me

Che
  • 11
  • 1
0

if your node_modules got installed in say /home/UserName/ like in my case, your package-lock.json file will also be there. just delete this file, go back to your app folder and run npm init and then npm install <pkgname> (e.g express) and a new node_modules folder will be created for your.

abulkhair
  • 1
  • 1
0

Seems you have installed express in root directory.Copy path of package.json and delete package json file and node_modules folder.

0

I had the same problem, I resolved by removing all insignificant lines in packages.json e only left "name", "version", "description", "devDependencies", "dependencies", "resolutions". and the error was gone.

The result package working is this

EACUAMBA
  • 461
  • 4
  • 8
0

I faced same problem. In my case it was directory permissions issue . I cloned using visual studio git plugin. It was solved once i cloned from git command line in another folder and executed git install there

harsha kumar Reddy
  • 1,251
  • 1
  • 20
  • 32
-2

the file path you ran is wrong. So if you are working on windows, go to the correct file location with cd and rerun from there.