kHRISl33t / runtime-env-cra

Runtime environment handler for create-react-apps
MIT License
49 stars 23 forks source link

using runtime-env-cra in React Hello World Application not working #20

Closed Jamal8548 closed 2 years ago

Jamal8548 commented 2 years ago

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:

sample@0.1.0 start cross-env NODE_ENV=development runtime-env-cra --config-name=./public/runtime-env.js && react-scripts start

'cross-env' is not recognized as an internal or external command,

if i do npm start with cross-env then error is as below:

sample@0.1.0 start NODE_ENV=development runtime-env-cra --config-name=./public/runtime-env.js && react-scripts start

'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.

Jamal8548 commented 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