question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"react-scripts-ts build" does not copy environment variables

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
zilionscommented, Feb 4, 2019

@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 with REACT_APP_.

Same info as my original post - I can access all environment variables prepended with REACT_APP_ when using react-scripts start, although they are all undefined after serving a build created with react-scripts build.

2reactions
jankalfuscommented, May 9, 2019

Don’t close

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found