Javascript 在node.js(Express)中导入json文件并导出到index.jsx(React)
我想将json文件导入到server.js文件中,然后将其导出。然后将导出的数据导入到我的index.jsx文件中。我能够将json数据提取到server.js文件中,并尝试使用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
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);