Closed Jamal8548 closed 2 years ago
I found a solution later ... npm install --save-dev cross-env start: cross-env NODE_ENV=development runtime-env-cra --config-name=./public/runtime-env.js && react-scripts start delete the file from public, it will be generated automatically
Step: 1 -> I created .env file in root and pasted NODE_ENV=production REACT_APP_API_URL = Jamal Ashraf Awan Step:2 -> using env variable in p tag
--- {window.__RUNTIME_CONFIG__.REACT_APP_API_URL}
Step:3 -> i created file in public named runtime-env.js and add window.__RUNTIME_CONFIG__ = {"NODE_ENV":"development","API_URL":"https://my-awesome-api.com"}; Step:4 -> modifiy start in package.json with : "start": "cross-env NODE_ENV=development runtime-env-cra --config-name=./public/runtime-env.js && react-scripts start",Now if i do npm start i got an error in command promt:
'cross-env' is not recognized as an internal or external command,
if i do npm start with cross-env then error is as below:
'NODE_ENV' is not recognized as an internal or external command,
Please help me , I am student and i want to use this library for the problem to make it possible to access a config file or environment variable during runtime on the server.