ember-cli-dotenv: This addon is incompatible with ember-cli@2.16.0-beta.2+
Hi.
Suddenly After updating to ember-cli@2.16.0-beta.2, ember-cli-dotenv stopped passing environment variables. In config/environment.js, process.env does not contain env vars from the dot-env file.
This happened to existing commits that have been working previously. My app uses Yarn with a proper lockfile, so I think it may be something with my OS.
Please help me debug this and figure out the reason.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 5
- Comments: 47 (6 by maintainers)
I have a fork going that moves the configuration out of ember-cli-build, which resolves this issue for now. https://github.com/jasonmit/ember-cli-dotenv
Readme diff summarizes the changes: https://github.com/jasonmit/ember-cli-dotenv/commit/b055555270217bec671f97d78f90b8d6181641cd#diff-04c6e90faac2675aa89e2176d2eec7d8
@fivetanley feel free to fold these changes in if you want. Otherwise I’ll continue to maintain the fork for others.
@SergeAstapov @jasonmit thanks for the awesome work through this thread - was tracing a few subtle bugs for a while, finally realized it was dotenv, and stumbled on this thread. After upgrading and migrating, everything works again.
Appreciate all the hard work!
@SergeAstapov @jasonmit sorry for the delay, you both have publish rights on npm. thanks so much for your help
Thank you @fivetanley! Version 2.0 has been pushed to npm! 🎉
Thank you all for the help, feedback and patience!
Has anyone gotten this updated version to work properly with
ember-cli-deploy? I keep gettingdevelopmentvariables rather than my other environments.@oxodesign changes are in master and will be published soon.
@jasonmit I added you and @SergeAstapov as collaborators on this repo. a 2.x release sounds great. It sounds like you have solved the issues on your fork? Feel free to merge those in.
@jeanduplessis for some reason
ember buildandember sworks differently:SOME_VAR_NAMEin.envlikeSergeAstapov/ember-cli-dotenv#update-ember-cliconfig/environment.jslikeAfter these steps do
ember buildand you should seeprocess.env.SOME_VAR_NAMEvariable value in meta tag in thedist/index.htmlfile:And CLI console output would be:
If you then would do
ember sCLI console output would be:and you would not see process.env.SOME_VAR_NAME variable value in meta tag in the dist/index.html file until you do some change and app is re-build.
What is current addon behavior:
read
.envfile inconfig()hook of addon. ember-cli <= 2.15 invokedconfig/environment.jsfile multiple times. Even afterconfig()hook of this addon. So as a resultprocess.envvariables from.envfile would became available next timeconfig/environment.jsis included. Change introduced in ember-cli@2.16 readsconfig/environment.jsonce and prior toconfig()hook of any addon.What was implemented in
SergeAstapov/ember-cli-dotenv#update-ember-cliread
.envfile inincluded()hook of addon This change still does not seem to solve the issue completely.What could be done else:
read
.envfile ininit()hook of addon. Problem would be thatember-cli-build.jsis not invoked yet and we do not have access to neitherdotEnvconfiguration options withinember-cli-build.jsnor we do not know what is the environment name build is running in (likedevelopment,testorproduction). This would allow us to read.envfile in project root prior toember-cli-build.jsorconfig/environment.jsfile is included and executed soprocess.envwould be available inconfig/environment.js.But on the other hand this change would prevent anyone from using custom
.envfile path or have per environment.envfiles (which does not considered as best practice at all, see dotenv README.md).Simple solution
Do not use
process.envwithinconfig/environment.jsYou can continue to use an addon withclientAllowedKeysas described in https://github.com/fivetanley/ember-cli-dotenv#what-is-ember-cli-dotenv. This would work in simple use cases but would not allow you to put some variable from.envinto nested object.I can’t see any better solution then what I have already implemented in SergeAstapov/ember-cli-dotenv#update-ember-cli. If anyone has any suggestions - would be glad to help.
Would be great to hear from @fivetanley who is original addon author.
@SergeAstapov while I can confirm that the values from our .env file gets added to environment config, we were previously using
process.env.KEY_NAMEin environment.js to set variables in a structure that other addons might expect.For example ember-intercom-api expects you to set the following:
and we were setting it as such:
Also we don’t use .env files on our production server so we rely on accessing the info via process.env.XXX so that it works both during local development as well as on production.
@jeffrey008
In terminal:
In your
ember-cli-build.js, do this:This will make env vars from your dotenv file available in the
process.env.In your
config/environment.js, do this:Then in your app you can do this: