Environment in `dotenv` files seems not correctly applied.
See original GitHub issueI 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:
- Created 5 years ago
- Reactions:3
- Comments:5 (2 by maintainers)
Top GitHub Comments
@patricklafrance @abenhamdine how can I access the variables in my .env from craco.config.js ? Currently am getting the value as undefined.
thx @patricklafrance ! 💃