简体   繁体   中英

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

Im getting the error Uncaught Error: ENOENT: no such file or directory, open 'names.json' and I have tried adding this code to my main.js:

const path = require('path');
const directory = path.join('data', 'names.json')

In builded version I get the err but when running the app with node it works.

Make sure you have the names.json file in the same folder as the.exe you are running.

The error explains the problem. "no such file or directory"

I can see in this line:

var names = JSON.parse(fs.readFileSync('names.json')).nameList;

The code is looking for the names.json file in the root of the application. You should be able to specify a folder structure as well. :)

eg: var names = JSON.parse(fs.readFileSync('./exampleFolder/names.json')).nameList;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM