Kinnard Hockenhull
Kinnard Hockenhull

Reputation: 3010

Error message "ENOENT, no such file or directory"

I'm getting this error from my Node.js application:

ENOENT, no such file or directory '~/Desktop/MyApp/newversion/partials/navigation.jade'

I know the file is there because when I try to open the file using the exact copied and pasted path, it works. I also know the application is using the right directory because, well, it outputs it in the error.

Upvotes: 104

Views: 535718

Answers (18)

Joao Marques
Joao Marques

Reputation: 113

You might have multiple npmrc configurations.

just run this:

npm config set registry "https://registry.npmjs.com/"

Upvotes: 0

grepit
grepit

Reputation: 22382

I believe the accepted answer is the correct answer to this problem but I was getting this error when I tried installing my npm package with npm install mailgun-js (see below):

Output for npm install mailgun-js

The fix for me was: npm init --yes

Output for the previous command npm init --yes, then checking with npm install mailgun-js

Upvotes: 51

half of a glazier
half of a glazier

Reputation: 2076

I was also plagued by this error, and after trying all the other answers, magically found the following solution:

Delete file package-lock.json and the node_modules folder, and then run npm install again.

If that doesn't work, try running these in order:

npm install
npm cache clean --force
npm install -g npm
npm install

(taken from @Thisuri's answer and @Mathias Falci's comment respectively)

And then re-deleting the above files and rerunning npm install.

It worked for me!

Upvotes: 22

sfscs
sfscs

Reputation: 525

For me, the trouble was caused by the fact that my code folder was a subdirectory of my Dropbox folder, on Windows 10. During the build process, the Dropbox application would complain about working with more than 500,000 files.

I moved my folder out from the Dropbox directory and now it builds fine!

Upvotes: 1

maxshuty
maxshuty

Reputation: 10662

Another possibility is that you are missing an .npmrc file if you are pulling any packages that are not publicly available.

You will need to add an .npmrc file at the root directory and add the private/internal registry inside of the .npmrc file like this:

registry=http://private.package.source/secret/npm-packages/

Upvotes: 0

tolache
tolache

Reputation: 179

My problem was that I didn't have a package.json file in my working directory.

Upvotes: 0

Arni Mikelsons
Arni Mikelsons

Reputation: 15

I ran into this upgrading a Phoenix app to 1.6, which does not use Node.js, so in fact it is not needed. However, elixir_buildpack.config had a reference to phoenix_static_buildpack.config, which defined node. Remove the reference, and the error goes away.

Upvotes: 0

Sachin
Sachin

Reputation: 336

Sometimes you are just not in the right directory. Check that once and try "npm start" again.

Upvotes: 0

It usually occurs due to a mismatch in the npm version used while creating the package-lock.json that currently exist and the one you are using now.

Removing the package-lock.json and running npm install worked for me.

Upvotes: 1

AnatuGreen
AnatuGreen

Reputation: 895

In my case, I was running the terminal in the wrong folder. Please make sure that you navigate to the folder containing your code (App.js and others) and then use a command prompt (for Windows) to open the code. I am using Visual Studio Code, so it is to type "code." after I have opened the command prompt in the exact folder where my code is in.

Upvotes: 0

Adam Hughes
Adam Hughes

Reputation: 16309

When this happened to me, it was when trying to run Karma tests in an Angular project. The tsconfig.spec.js file turned out to be incorrect. It was basically pointing to the wrong directory, and so the error was simply trying to tell me this.

Enter image description here

For example, we had ../tsconfig.json instead of ./tsconfig.json, so the runner was looking for tests in the wrong folder. This may be a different use case from the OP, but the same error message brought me here and led me down the rabbit hole of trying the npm install solutions to no avail.

Upvotes: 1

BraveNewMath
BraveNewMath

Reputation: 8323

__dirname

Gives you the current Node.js application's root directory.

In your case, you'd use

__dirname + '/Desktop/MyApp/newversion/partials/navigation.jade';

See this answer:

How can I get the application base path from a module in Node.js?

Upvotes: 10

Earl Lapura
Earl Lapura

Reputation: 175

For those running Laravel Mix with npm run watch, just terminate the script and run the command again.

Upvotes: 2

Thisuri
Thisuri

Reputation: 409

  1. First try npm install. If the issue is not yet fixed, try the following one after the other.
  2. npm cache clean, then
  3. npm install -g npm , then npm install. Finally
  4. ng serve --o to run the project.

Upvotes: 20

Sanjay
Sanjay

Reputation: 1007

I had that issue using the path module:

const path = require('path');

And also do not forget to create the uploads directory first period.

Upvotes: 4

Aleksei Burov
Aleksei Burov

Reputation: 43

Reason: I have the same issue, where a few guys work on one project and change package dependencies.

Solution: Just kill file package-lock.json and run npm i again

Upvotes: 0

Fillip Peyton
Fillip Peyton

Reputation: 3657

Specifically, rm yarn.lock and then yarn install fixed this for me.

Upvotes: 2

hobbs
hobbs

Reputation: 239841

Tilde expansion is a shell thing. Write the proper pathname (probably /home/yourusername/Desktop/etcetcetc) or use
process.env.HOME + '/Desktop/blahblahblah'

Upvotes: 31

Related Questions