简体   繁体   中英

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. And then import that exported data in my index.jsx file. 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.

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

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

index.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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM