1

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);
Neel Dsouza
  • 1,342
  • 4
  • 15
  • 33

1 Answers1

1

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);
Akshay Sharma
  • 1,042
  • 1
  • 8
  • 21