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.

Environment in `dotenv` files seems not correctly applied.

See original GitHub issue

I am setting PUBLIC_URL on .env.production but it seems that .env* files are not read while building (and overriding) the webpack configuration. Indeed, the configuration of the InterploateHtmlPlugin does not “see” the variables I set on these files, while the message at the end of the build (The project was built assuming it is hosted at /MY_PUBLIC_URL) correctly reports it. If I add require(resolveConfigFilePath("env.js")); before line https://github.com/sharegate/craco/blob/c4e8dd40aa875fcef02467dac444122bbf241956/packages/craco/lib/cra.js#L20 everything works. Indeed, the original script react-scripts/scripts/build.js loads the environment before building the configuration (see https://github.com/facebook/create-react-app/blob/45bc6280d109b7e353ffaa497a0352c9d040c36d/packages/react-scripts/scripts/build.js#L22).

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
ajaijcommented, Oct 21, 2020

@patricklafrance @abenhamdine how can I access the variables in my .env from craco.config.js ? Currently am getting the value as undefined.

/* .env */
REACT_APP_FOO="bar"

/* craco.config.js */
console.log('env....', process.env.REACT_APP_FOO);  // getting undefined here
1reaction
abenhamdinecommented, Jan 18, 2019

thx @patricklafrance ! 💃

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotenv file is not loading environment variables - Stack Overflow
env file relative to the current working directory from where the application was launched. You can create this path like this: const path...
Read more >
5 reasons why your .env environment variables don't work
1. Your framework doesn't automatically load .env files. ... While some frameworks and packages come built-in support for environment variables ...
Read more >
Managing .env files and setting variables - Prisma
Learn how to manage .env files and set environment variables.
Read more >
Why syncing .env files doesn't scale for secrets management
Libraries such as Python's dotenv and Node's dotenv made it easy for developers to use .env files and environment variables for application ...
Read more >
What is .env ? How to Set up and run a .env file in Node?
Environment variables in Node are used to store sensitive data such as passwords, API credentials, and other information that should not be ...
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