Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在node.js(Express)中导入json文件并导出到index.jsx(React)_Javascript_Node.js_Reactjs_Express - Fatal编程技术网

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

Javascript 在node.js(Express)中导入json文件并导出到index.jsx(React),javascript,node.js,reactjs,express,Javascript,Node.js,Reactjs,Express,我想将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 Pr

我想将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
const confiq = require("../public/json/config.json");
module.exports = config; // exporting the config 


您正在从“服务器”导入conf,您必须在服务器中导出它这是否回答了您的问题?您正在server.js中导出confiq,它应该是conf
// index.jsx

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