question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: ENOENT: no such file or directory, open '. /file.json'

See original GitHub issue

It cannot seem to find the files which are there. I was able to require the file I needed as js with the same exact path save for the extension. To be sure the issue was not caused by a file path typo I did the following:

echo "{}" > file.json

Then in the importing file in the same directory:

const loadJsonFile = require('load-json-file');
 
loadJsonFile('./file.json').then(json => {
    console.log(json);
    //=> {foo: true} 
});

which produced the error: Error: ENOENT: no such file or directory, open '. /file.json'

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

34reactions
SamVerschuerencommented, Jul 31, 2017

If you want it relative to the source file, path.join(__dirname, 'file.json')

19reactions
sindresorhuscommented, Jul 30, 2017

Make sure the process.cwd() (try logging it) is correct. ./file.json is relative from where the Node.js process was started, not where the source file is.

Read more comments on GitHub >

github_iconTop Results From Across the Web

npm - How to resolve Node.js: "Error: ENOENT: no such file or ...
Your app is expecting to find a file at /home/embah/node/nodeapp/config/config.json but that file does not exist (which is what ENOENT ...
Read more >
Error: ENOENT: no such file or directory ... - Node-RED Forum
Hello Everyone,. I have recently upgraded by docker image of node-red to 2.1.4. While i deploy the the node-red pod in kubernetes i...
Read more >
ENOENT No Such File or Directory Open - YouTube
In This Video We Will See How to Fix npm ERR Code ENOENT npm ERR syscall Open Error or ENOENT No Such File...
Read more >
Node.js Error: ENOENT: no such file or directory (2023)
Error : ENOENT: no such file or directory · This problem occurs when a file does not exist; therefore, check to see if...
Read more >
no such file or directory, open '/usr/app/package.json' CI error ...
Npm ERR! enoent ENOENT: no such file or directory, open '/usr/app/package.json' CI error but works locally ... Another thing to try would be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found