npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Nuwanst\package.json'

341,038

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
Share:
341,038
Admin
Author by

Admin

Updated on September 21, 2021

Comments

  • Admin
    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
    Rehmat over 4 years
    Rsynced all my apps from one server to another and package-lock.json was present there. Deleting it from all apps saved my day.
  • sean
    sean over 4 years
    Don't add this to source control I am guessing?
  • Aravin
    Aravin over 4 years
    Yes, this file should be added to .gitignore file
  • towry
    towry almost 4 years
    I don't have package-lock.json.
  • Aakash Goplani
    Aakash Goplani almost 4 years
    What are the steps to give yourself full control?
  • Sheep
    Sheep almost 4 years
    @KinleyChristian right click on the folder, select Properties, then go into the security tab.
  • Dijiflex
    Dijiflex almost 4 years
    This 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
    Dijiflex almost 4 years
    Thanks it was added after the installation
  • Duc Nguyen
    Duc Nguyen over 3 years
    it worked for me, but can you explain this solution?
  • Jatin Mehrotra
    Jatin Mehrotra over 3 years
    Post a code along with the reason for better understanding.
  • VoteCoffee
    VoteCoffee over 3 years
    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.
  • Sisir
    Sisir almost 3 years
    Most of the cases this is not the correct answer. Please check @Aravin's answer
  • Ziv
    Ziv over 2 years
    Please don't run sudo chmod -R 777 * on your workspace.
  • Régis NIOX
    Régis NIOX over 2 years
    After 1 hour of fight, your solution worked for me. Thanks!
  • Aravin
    Aravin over 2 years
    Glad to know that @RégisNIOX
  • Janos Vinceller
    Janos Vinceller almost 2 years
    this is quite dangerous, some people have no clue, you are recommending to give all rights to every file
  • Asotos
    Asotos almost 2 years
    This file should be added to source control. In order to install from it instead of from package.json one can use npm ci.
  • Asotos
    Asotos almost 2 years
    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?