在node.js(Express)中导入json文件并导出到index.jsx(React)



我想将一个 json 文件导入我的服务器.js文件,然后将其导出。然后将导出的数据导入我的 index.jsx 文件中。我能够将 json 数据提取到我的服务器.js文件中,并尝试使用export.modulesexport default config导出它,但是当我在我的 index.jsx 文件中导入它时出现错误。

ERROR in ./node_modules/destroy/index.js
Module not found: Error: Can't resolve 'fs' in 'D:React ProjectsSearchUInode_modulesdestroy'
ERROR in ./node_modules/send/index.js
Module not found: Error: Can't resolve 'fs' in 'D:React ProjectsSearchUInode_modulessend'
ERROR in ./node_modules/express/lib/request.js
Module not found: Error: Can't resolve 'net' in 'D:React ProjectsSearchUInode_modulesexpresslib

以下是我迄今为止尝试的代码:服务器.js

const confiq = require("../public/json/config.json");
module.exports = config;

索引.jsx

import config from "../server/server";
console.log(config);

这应该是:

// server.js
const confiq = require("../public/json/config.json");
module.exports = config; // exporting the config 
// index.jsx
import confiq from "../server/server"; // importing the config
console.log(confiq);

相关内容

最新更新