kentcdodds / cross-env

🔀 Cross platform setting of environment scripts
https://www.npmjs.com/package/cross-env
MIT License
6.32k stars 243 forks source link

No custom variable available without REACT_APP_ prefix #220

Closed michalpaukert closed 4 years ago

michalpaukert commented 4 years ago

What you did:

"start-cz": "cross-env LANG=cz react-scripts start"

What happened:

console.log(process.env);

{NODE_ENV: "development", PUBLIC_URL: ""}

Reproduction repository:

Problem description: When I run my package.json script I cant get my custom variable, it only works when I use REACTAPP* variables or NODE_ENV

Suggested solution: create process env variables for every custom variable.

kentcdodds commented 4 years ago

This is actually how react-scripts works. It's an intentional feature. cross-env is doing things correctly. It's just that react-scripts wont make all env variables available to your frontend code.

Read more: https://create-react-app.dev/docs/adding-custom-environment-variables/

Good luck :)