我想在 api 路由文件中使用 fs 模块来执行一些文件系统操作,但是,我收到此错误:Module not found: Can't resolve 'fs'。我不仅无法在处理程序函数中使用 fs,而且还无法启动项目,因为 fs 错误阻止了这一点。
这就是我的文件的样子。
小路:pages/api/getSchema.js
内容:
const fs = require("fs");
export default function handler(req, res) {
const id = req.query.id;
if(id){
const schemas = require('../../pageSchemas/index.json');
res.end(JSON.stringify(schemas[id]));
}
}
Run Code Online (Sandbox Code Playgroud)