[英]Import json file in node.js(Express) and export to index.jsx(React)
I want to import a json file into my server.js file and then export it.我想将一个 json 文件导入到我的 server.js 文件中,然后将其导出。 And then import that exported data in my index.jsx file.
然后在我的 index.jsx 文件中导入导出的数据。 I'm able to fetch the json data into my server.js file and also tried to export it using
export.modules
and export default config
but I'm getting an error while I'm importing it in my index.jsx file.我能够将 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
Following is the my code what i tried till now: server.js以下是我迄今为止尝试过的代码: server.js
const confiq = require("../public/json/config.json");
module.exports = config;
index.jsx索引.jsx
import config from "../server/server";
console.log(config);
This should be :这应该是:
// 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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.