ENOENT: 没有那个文件或目录,打开 'Filename'
ENOENT: no such file or directory, open 'Filename'
我需要来自 .json 文件的一些数据,但出现此错误:
Error: ENOENT: no such file or directory, open '../Jsons/eshop.json'
at Object.openSync (node:fs:585:3)
at Object.readFileSync (node:fs:453:35)
at Object.execute (C:\Users\Pooyan\Desktop\PDM Bot Main\commands\shop.js:9:24)
at module.exports (C:\Users\Pooyan\Desktop\PDM Bot Main\events\guild\message.js:114:15)
errno: -4058,
syscall: 'open',
code: 'ENOENT',
path: '../Jsons/eshop.json'
}
我的代码:
let shop_data = JSON.parse(Buffer.from(fs.readFileSync('../Jsons/eshop.json')).toString());
let index = (args[0] || "1");
let page = shop_data.pages[index];
我认为这就是您所需要的,但如果需要任何其他代码,请对其进行评论。
我正在使用 discord.js v13 和 node.js 16
问题出在路径上。给定的 eshop.json
文件的路径似乎无效,或者路径中可能存在任何拼写错误。
fs.readFileSync
取相对路径:
- test.js
- JSON
- 样本JSON
- eshop.json
fs.readFileSync('./JSON/sampleJSON/eshop.json');
我需要来自 .json 文件的一些数据,但出现此错误:
Error: ENOENT: no such file or directory, open '../Jsons/eshop.json'
at Object.openSync (node:fs:585:3)
at Object.readFileSync (node:fs:453:35)
at Object.execute (C:\Users\Pooyan\Desktop\PDM Bot Main\commands\shop.js:9:24)
at module.exports (C:\Users\Pooyan\Desktop\PDM Bot Main\events\guild\message.js:114:15)
errno: -4058,
syscall: 'open',
code: 'ENOENT',
path: '../Jsons/eshop.json'
}
我的代码:
let shop_data = JSON.parse(Buffer.from(fs.readFileSync('../Jsons/eshop.json')).toString());
let index = (args[0] || "1");
let page = shop_data.pages[index];
我认为这就是您所需要的,但如果需要任何其他代码,请对其进行评论。 我正在使用 discord.js v13 和 node.js 16
问题出在路径上。给定的 eshop.json
文件的路径似乎无效,或者路径中可能存在任何拼写错误。
fs.readFileSync
取相对路径:
- test.js
- JSON
- 样本JSON
- eshop.json
- 样本JSON
fs.readFileSync('./JSON/sampleJSON/eshop.json');