Snowcrash
Snowcrash

Reputation: 86337

npm ERR! enoent ENOENT: no such file or directory, open package.json

I'm new to Node so bear with me.

I have a Node server which requires ws so I install it with:

$ npm install ws
/private/var/www/html/WebRTC/SVC
└─┬ ws@1.1.1 
  ├── options@0.0.6 
  └── ultron@1.0.2 

npm WARN enoent ENOENT: no such file or directory, open '/private/var/www/html/WebRTC/SVC/package.json'
npm WARN SVC No description
npm WARN SVC No repository field.
npm WARN SVC No README data
npm WARN SVC No license field.

I then run the server using:

$ npm run server.js 
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/Cellar/node/6.2.2/bin/node" "/usr/local/bin/npm" "run" "server.js"
npm ERR! node v6.2.2
npm ERR! npm  v3.9.5
npm ERR! path /private/var/www/html/WebRTC/SVC/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open

npm ERR! enoent ENOENT: no such file or directory, open '/private/var/www/html/WebRTC/SVC/package.json'
npm ERR! enoent ENOENT: no such file or directory, open '/private/var/www/html/WebRTC/SVC/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! Please include the following file with any support request:
npm ERR!     /private/var/www/html/WebRTC/SVC/npm-debug.log

but am getting errors mentioning no package.json.

Looking through npm-debug.log it seems pretty much the same.

Can someone shed some light on what enoent is and what sort of package.json file I need.

I was expecting this script to run out of the box so a little puzzled.

Upvotes: 0

Views: 44875

Answers (8)

Divyaa01
Divyaa01

Reputation: 1

Just check if you are in the correct folder. For me, when I had the same error, I was not in the same directory as the package.json file. Hence, my npm was not able to find it.

Once i had changed the directory. the issue got solved.

Upvotes: 0

Deepthi Reddy
Deepthi Reddy

Reputation: 1

npm error code ENOENT
npm error syscall lstat
npm error path C:\Users\yourUsername\AppData\Roaming\npm
npm error errno -4058
npm error enoent ENOENT: no such file or directory, lstat 'C:\Users\yourUsername\AppData\Roaming\npm'
npm error enoent This is related to npm not being able to find a file.
npm error enoent

npm error A complete log of this run can be found in: C:\Users\yourUsername\AppData\Local\npm-cache\_logs\2024-07-09T10_24_04_497Z-debug-0.log

To Resolve the above error in vs code:

Firstly, check whether the folder having all the permissions or not if not

Right click on the folder > Properties > security > Allow all permissions and make sure to uncheck the read-only option in general.

Upvotes: 0

Ismail Khan
Ismail Khan

Reputation: 1

I had same issue solved like this:

Just run this command: npm config set legacy-peer-deps true

& then

npm install

Upvotes: 0

ALGIN SHAJI
ALGIN SHAJI

Reputation: 1

Try this in cmd, it will work for sure! Navigate to this file.

cd C:\Users\hp\AppData\Roaming

then enter

mkdir npm

Upvotes: 0

DushyanthaAT
DushyanthaAT

Reputation: 11

Try following steps

  1. Reinstall npm: open cmd as an administrator and run npm uninstall -g npm
  2. Go to your directory and open cmd
  3. Clear npm Cache using npm cache clean -f
  4. Now you can update npm using npm install -g npm@latest

Upvotes: 1

Muhammad Luqman
Muhammad Luqman

Reputation: 3

Following commands worked for me:

npm cache clean --force
node server.js

Upvotes: 0

Samanue Santhosh
Samanue Santhosh

Reputation: 11

This command works for me:

npm install -g expo-cli --force

Upvotes: 1

Sergey Lapin
Sergey Lapin

Reputation: 2693

When you type

npm run server.js

npm tries to find entry named server.js in the scripts section of your package.json file (see npm docs on scripts for details).

package.json, simplified, describes your app's dependencies and environment.

As you don't have such file, npm fails with ENOENT, which is an abbreviation for Error NO ENTry. Basically, in your case, you just want to node server.js to run your script.

Upvotes: 1

Related Questions