I want to use a config.json file located in root directory in React. The reason of this is because i will need update this file json whitout rebuild project.
Project estructure:
> /build
> /node_modules
> /public
> /src
> config.json
> package.json
...ect.
What i try?
[Try 1] Import from root directory..
import { configUrl } from "./../../config.json";
[Try 2] Add into dependencies
"@project-name": "file:./config.json"
And import into react component
import { configUrl } from "@project-name";
To finally use fetch:
return fetch(configUrl, requestOptions)
.then((response) => response.json())
.then((result) => {
console.log(result);
return result;
})
.catch((error) => console.log("error", error));
But noone work, what more can i do?