Alex
Alex

Reputation: 3072

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

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?

Upvotes: 39

Views: 158901

Answers (10)

Kishore Selvam
Kishore Selvam

Reputation: 1

I had a similar problem like this.

I simply went to the node installation file and copied that npm file from the below path. C:\Program Files\nodejs\node_modules\npm

And as the terminal/command prompt shows: no such file or directory C:\Users\YourSystemName\AppData\Roaming\npm. I paste that I have copied from the installation file as per the above mentioned in the path C:\Users\YourSystemName\AppData\Roaming\copiedfile(npm)).

After that, it's working properly for me.

Upvotes: 0

Krishna Choudhari
Krishna Choudhari

Reputation: 476

you have first enter npm init command then use command

npm install -g [email protected]

then use npx

Upvotes: 0

Deepak paramesh
Deepak paramesh

Reputation: 864

Delete you package-lock.json and then run the command npm i.

You can then create back the package-lock.json with the command.

npm i --package-lock-only

Upvotes: 0

mpolokn
mpolokn

Reputation: 1

i fixed it by cd into the folder in the terminal

Upvotes: 0

Sonia
Sonia

Reputation: 127

I deleted the package-lock.json and It worked for me.

Upvotes: 7

Chris
Chris

Reputation: 123

If you are working on a Windows machine using Vagrant/VM, there's a chance that symlinks are the culprit for your problem. To determine if that is the case, simply copy your package.json and package-lock.json into a test directory that is not mounted/shared between OSs.

mkdir /tmp/symlinktest
cd {{your directory with your package*.json}}
cp package*.json /tmp/symlinktest
cd /tmp/symlinktest
npm install

If this results in a successful install, you'll need to either exclude the node_modules directory from the mount (there's various articles on doing this, however I can't say I've had success) or run npm install outside the mounted volume.

Upvotes: 9

Vicky
Vicky

Reputation: 642

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.

Upvotes: 51

Mushtaque Ahmed
Mushtaque Ahmed

Reputation: 303

Check the project folder which you opened in microsoft visual code. Generally you are not in the right path so npm is not able to search the package.json ... My project was in Document/hostel/hostel .. I opened Document/hostel ... So npm tried to find the package.json in Documents folder .. When i entered one level inside to Document/hostel/hostel .. it was fixed.

Upvotes: 0

Aravindh Sivalingam
Aravindh Sivalingam

Reputation: 127

Basically I was Offline while I tried to install with npm, so go online and try npm install again

Upvotes: 3

DAXaholic
DAXaholic

Reputation: 35398

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.

Upvotes: 26

Related Questions