Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install resulting in 'ENOENT: no such file or directory'

Tags:

node.js

npm

I've installed Node.js for Windows and I'm trying to install a package via npm. The command prompt is in the directory of the project (C:\Users\username\Desktop\NodeTest), which contains a single helloworld.js file. Upon typing 'npm install express', I receive the following error:

ENOENT: no such file or direcotry, open 'C:\Users\username\package.json

I'm attempting this from a clean install and cmd is running as admin.

Any ideas?

like image 803
Alex Godbehere Avatar asked Jul 01 '16 10:07

Alex Godbehere


People also ask

How do I fix Enoent No such file or directory open?

To resolve the ENOENT warning message, you need to add a package. json file in the directory where you run the npm install command. And then run your npm install command again. This time, the warning message should not appear.

How do I fix error 4058?

The only way to solve it was to close VSCode, remove node_modules from examples/simple and run npm install directly from the terminal/bash (inside examples/simple ). The problem, in my case, was that VSCode kept cached the package-lock. json from the root directory and it caused conflicts.


2 Answers

I was facing the same issue. I firstly delete my node_modules and delete the cache by following command:

rm -rf node_modules && npm cache clean --force

then I delete the package-lock.json file from my project and then hit npm install in command prompt and it works.

like image 94
Vicky Avatar answered Oct 16 '22 09:10

Vicky


As already pointed out by Subburaj this is because you are missing a package.json.
Just run npm init to initialize that file for you; afterwards it should work.

like image 22
DAXaholic Avatar answered Oct 16 '22 07:10

DAXaholic