I have a ipAddress.json file that has the contents:
{
"ipAddress": "11.111.111.111"
}
In the public folder i put that ipAddress.json file into an "ipAddress" folder so the path looks like "public/ipAddress/ipAddress.json"
But I cannot read this file. I am trying
const ipAddress = (require(process.env.PUBLIC_URL + '/ipAddress/ipAddress.json')).ipAddress;
using "json-loader" common library.
How do I get this to work? According to (Using the Public Folder) it should work just fine.
But I get this error:
Module not found: You attempted to import /ipAddress/ipAddress.json which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.
Thank you for any help
If its just a json object you should be able to create a js file with the data inside a const object. Then export the const as a module.
New JS file to create:
const ipAddressJson = {
ipAddress: "11.111.111.111"
};
module.exports = ipAddressJson;
Inside the file you want the json object:
import ipAddressJson from 'path-to-the-js-file-above';
https://codesandbox.io/embed/tender-bash-2hjei
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With