-
-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reference to env vars sitting outside main config yml causes error #38
Comments
The same happens to me. I have different environment files per stage, and quite annoying to see the warning every time I run a serverless command. |
I'm getting the same error, any update about this issue? |
No updates, sorry. I haven't had many resources to set aside and look deeper into this. It's a plugin that works fairly well for most people in most use-cases. If you'd like to take a look at the code and see how it could be improved, that would be really helpful. |
same issue here :(. any idea how to solve this? update: I had a look at the code and I figure out the issue. in let tmpEnvVars = {};
Object.keys(envVars).forEach(key => {
console.log(key);
if (this.logging) {
this.serverless.cli.log('\t - ' + key)
}
tmpEnvVars[key] = envVars[key];
})
this.serverless.service.provider.environment = tmpEnvVars; the idea is this assignment is wong in case enviroment is set to load from different file [${file(./serverless_variables/environment_variables.yml):${env:NODE_ENV,development}}] = envVars[key] //which is wrong @colynb can you have a look? if the changes can be applied, I can open a PR. Thanks |
You can read from https://www.serverless.com/framework/docs/providers/aws/guide/plugins/#plugins/: Variable references in the serverless instance are not resolved before a Plugin's constructor is called, so if you need these, make sure to wait to access those from your hooks. In this case the method loadEnv is being called in the constructor of the plugin, causing the known issue since the references have not been resolved at that point. |
Thanks for the investigation! This plugin does two different things:
Doing 1) in the constructor is handy because it ensures the environment variables are loaded pretty much before anything else can happen. This bug happens while trying to do 2). I think the best workaround for this is to manually wire up the environment variables yourself:
Setting serverless-dotenv-plugin/index.js Lines 120 to 123 in 2b66c15
|
FYI I have updated the README with this issue and the workaround: #108 |
Thanks for the feedback. If I find the time I'll try to find a definitive solution. Would you be willing to accept a pull request on this? |
I'm open to a solution, but maybe it's better to discuss it here first. Just looking to avoid a situation where you have a full pull request and a disagreement arises that causes rework 🙂. |
I agree. I will think some solution for this and let you know here. |
|
Closed due to inactivity. Please reopen when you get a chance to respond. |
Error:
configs:
serverless.yml
serverless-env.yml
No errors when moving
environment
to outside theprovider
. Verified that it's working perfectly when it's located outsideprovider
.The text was updated successfully, but these errors were encountered: