I have a react project where I am trying to import some data from a json file that sits outsite of the project.
I am attempting to import it like:
const env = require('./../../env.json');
I get the following error:
Module not found: Error: You attempted to import ./../../env.json which falls outside of the project src/ directory. Relative imports outside of src/ are not supported. [1] You can either move it inside src/, or add a symlink to it from project's node_modules/.
I don't fully understand how it is possible to get data from outside of the project. I attempted using dotenv but had no luck :/
How is it possible to create the symlink?
Also, if the symlink is created locally, when I deploy to the server will the symlink still work? Is it saved in the project or would I need to add symlinks again on the server?
Any help on how to get access to data from outside my react project would be appreciated.
I have a project where I have multiple react applications that need to use the same json data.
I have the following directory sturcture:
-Project Root
--server.js
--env.json
--react-app-1
--react-app-2