"react-scripts-ts build" does not copy environment variables
See original GitHub issueI am setting some environment variables in my build script, like so:
"start": "REACT_APP_APPENV=local npm-run-all -p watch-css react-scripts-ts start",
"build": "REACT_APP_APPENV=production npm run build-css && react-scripts-ts build"
My start
script works perfectly and I am able to access REACT_APP_APPENV
via process.env. REACT_APP_APPENV
.
Although my build
script does not copy over REACT_APP_APPENV
, and process.env. REACT_APP_APPENV
is undefined
.
I tried creating a fresh new project via npx create-react-app new-app --typescript
and the same issue occurred.
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (4 by maintainers)
Top Results From Across the Web
create react app not picking up .env files? - Stack Overflow
in my case I was copy file from different OS and use in ubuntu system so just I did "sudo touch .env" and...
Read more >Adding Custom Environment Variables | Create React App
Environment variables are embedded into the build, meaning anyone can view them by inspecting your app's files.
Read more >How to dynamically change your React Environment variables ...
We were looking to build something that fulfilled the following: Does not require a rebuild; Minimal code change required; Allows synchronous ...
Read more >Handling runtime environment variables in create-react-apps
A new package called runtime-env-cra allows you to handle environment variables in quick and easy way with create-react-apps.
Read more >Using environment variables in a React application
When using create-react-app, the variable needs to start with REACT_APP_ otherwise this won't work, and it's mostly for security reasons. It's a good...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mrmckeb - I migrated my project to
create-react-app
and the issue is still present.react-scripts build
fails to copy environment variables that are prepended withREACT_APP_
.Same info as my original post - I can access all environment variables prepended with
REACT_APP_
when usingreact-scripts start
, although they are allundefined
after serving a build created withreact-scripts build
.Don’t close