following this article https://serverless-stack.com/chapters/environments-in-create-react-app.html
I am trying to add an environment variable to my react app which I have created using create react app. so my build command looks like below
"build": "REACT_APP_SECRET_CODE=123 react-scripts build",
while I try to run this build command in my Visual studio code terminal via
npm run build
it gives me the error that REACT_APP_SECRET_CODE is not recognized as an internal or external command.
How would i pass the environment variable in `package.json and build my app and access the variable value in my app.
If you don't want to install any other library. You can pass environment variable to yarn or npm command like this:
"scripts": {
"start": "breact-scripts start",
"start:env": "REACT_APP_ABC=xyz yarn start",
}
Note: Remember to put prefix "REACT_APP_" in your environment variable otherwise React won't allow it to use in app.
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