我的index.js中有以下代码
const config = require('./config.json');我的config.json的内容是
{
"default_prefix": "?"
}但是我得到了一个错误: TypeError:只支持绝对URL。导致该错误的原因是什么?
如果我必须显示更多的代码,请在评论中问我。
发布于 2020-09-13 16:54:33
./config.json是一个相对URL,它请求一个绝对URL。
尝试将其转换为绝对URL:https://stackoverflow.com/a/38829194/2875073
const configAbsolutePath = require('path').resolve('./config.json')
const config = require(configAbsolutePath);或者您可以尝试在这里使用另一个选项来读取json文件:Using Node.JS, how do I read a JSON file into (server) memory?
https://stackoverflow.com/questions/63868810
复制相似问题