npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Nuwanst\package.json'
Solution 1
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.
Solution 2
If you already have package-lock.json
file just delete it and try again.
Solution 3
Make sure you are on the right directory where you have package.json
Solution 4
You need to make sure if package.json file exist in app folder. i run into same problem differently but solution would be same
Run this command where "package.json" file exist. even i experience similar problem then i change the folder and got resolve it. for more explanation i run c:\selfPractice> npm start whereas my package.json resides in c:\selfPractice\frontend> then i change the folder and run c:\selfPractice\frontend> npm start and it got run
Solution 5
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
Admin
Updated on September 21, 2021Comments
-
Admin over 2 years
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 `-- [email protected] 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.
-
Rehmat over 4 yearsRsynced all my apps from one server to another and package-lock.json was present there. Deleting it from all apps saved my day.
-
sean over 4 yearsDon't add this to source control I am guessing?
-
Aravin over 4 yearsYes, this file should be added to
.gitignore
file -
towry almost 4 yearsI don't have package-lock.json.
-
Aakash Goplani almost 4 yearsWhat are the steps to give yourself full control?
-
Sheep almost 4 years@KinleyChristian right click on the folder, select Properties, then go into the security tab.
-
Dijiflex almost 4 yearsThis worked for me after deleting the package-lock.json. Now my question is will the package-lock.json be reacreted after running npm instal? @Aravin Because I am in he install process and i am not seeing it creating the the package-lock.json
-
Dijiflex almost 4 yearsThanks it was added after the installation
-
Duc Nguyen over 3 yearsit worked for me, but can you explain this solution?
-
Jatin Mehrotra over 3 yearsPost a code along with the reason for better understanding.
-
VoteCoffee over 3 yearsThis 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.
-
Sisir almost 3 yearsMost of the cases this is not the correct answer. Please check @Aravin's answer
-
Ziv over 2 yearsPlease don't run
sudo chmod -R 777 *
on your workspace. -
Régis NIOX over 2 yearsAfter 1 hour of fight, your solution worked for me. Thanks!
-
Aravin over 2 yearsGlad to know that @RégisNIOX
-
Janos Vinceller almost 2 yearsthis is quite dangerous, some people have no clue, you are recommending to give all rights to every file
-
Asotos almost 2 yearsThis file should be added to source control. In order to install from it instead of from
package.json
one can usenpm ci
. -
Asotos almost 2 yearsAravin'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?