kentcdodds / cross-env

🔀 Cross platform setting of environment scripts

Home Page:https://www.npmjs.com/package/cross-env

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No custom variable available without REACT_APP_ prefix

michalpaukert opened this issue · comments

  • cross-env version: 6.0.3
  • node version: 12.13.0
  • npm (or yarn) version: 6.13.1

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 REACT_APP_* variables or NODE_ENV

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

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 :)