ENOENT, no such file or directory

I'm getting this error from my node app:

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.

353401 次浏览

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

I believe the previous answer is the correct answer to this problem but I was getting this error when I tried installing npm package (see below) :

enter image description here

The fix for me was : npm init --yes

enter image description here

I had that issue : use path module

const path = require('path');

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

  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. Hope this will help....

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

__dirname

Gives you the current node application's rooth directory.

In your case, you'd use

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

See this answer:

App base path from a module in NodeJS

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/

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

Delete package-lock.json and the node_modules folder, 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 re-running npm install.

Worked for me!

For me, it was having my code folder in Dropbox on windows 10. During the build process Dropbox would flip out over having more than 500,000 files. I moved my folder out and now it builds fine!

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

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

When this happened to me, it was when trying to run karma tests in an angulare 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 runner was looking for tests in the wrong folder. This may be different usecase from OP, but same error message brought me here and led me down the rabbit hole of trying the npm install solutions to no avail.

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 Command prompt (for Windows) to open the code. I am using VS code so it is to type "code." after I have opened Command prompt in the exact folder where my code is in.

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

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

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

Ran into this upgrading an Phoenix app to 1.6, which does not use node, 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.

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