【发布时间】:2019-12-16 17:34:30
【问题描述】:
我想将一个 json 文件导入到我的 server.js 文件中,然后将其导出。然后将导出的数据导入我的 index.jsx 文件中。我能够将 json 数据提取到我的 server.js 文件中,并且还尝试使用 export.modules 和 export default config 将其导出,但在我的 index.jsx 文件中导入它时出现错误。
ERROR in ./node_modules/destroy/index.js
Module not found: Error: Can't resolve 'fs' in 'D:\React Projects\SearchUI\node_modules\destroy'
ERROR in ./node_modules/send/index.js
Module not found: Error: Can't resolve 'fs' in 'D:\React Projects\SearchUI\node_modules\send'
ERROR in ./node_modules/express/lib/request.js
Module not found: Error: Can't resolve 'net' in 'D:\React Projects\SearchUI\node_modules\express\lib
以下是我到目前为止尝试的代码: server.js
const confiq = require("../public/json/config.json");
module.exports = config;
index.jsx
import config from "../server/server";
console.log(config);
【问题讨论】:
-
你正在从“服务器”导入配置文件,你必须在服务器中导出它
-
你在 server.js 中导出 confiq,应该是 conf
标签: javascript node.js reactjs express