You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reference to env vars sitting outside main config yml causes error #38
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.
the idea is this assignment is wong in case enviroment is set to load from different file this.serverless.service.provider.environment[key] = envVars[key]
and it will cause the following if environment is set to (as an eample ${file(./serverless_variables/environment_variables.yml):${env:NODE_ENV,development}})
[${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.
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.
Load all environment variables defined in dotenv file(s) into the Serverless environment
By default, assign all environment variables to provider.environment
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:
custom:
dotenv:
include: []
Setting dotenv.include to [] will cause the plugin to bypass any interaction with provider.environment because it will result in envVars being an empty list:
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 🙂.
serverless>=2.26.0 should resolve this issue, although it may cause other breaking issues. Please see the README (relevant changes: #149) for more details.
Activity
mgarciadelojo commentedon Jun 3, 2019
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.
mattia85 commentedon Jan 3, 2020
I'm getting the same error, any update about this issue?
colynb commentedon Jan 6, 2020
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.
Ali-Dalal commentedon Jul 22, 2020
same issue here :(. any idea how to solve this?
update:
I had a look at the code and I figure out the issue.
in
index.jswe need to replace lines
74to79with the following:the idea is this assignment is wong in case enviroment is set to load from different file
this.serverless.service.provider.environment[key] = envVars[key]and it will cause the following if environment is set to (as an eample
${file(./serverless_variables/environment_variables.yml):${env:NODE_ENV,development}})@colynb can you have a look? if the changes can be applied, I can open a PR.
Thanks
RaydelMiranda commentedon Feb 2, 2021
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.
neverendingqs commentedon Feb 6, 2021
Thanks for the investigation!
This plugin does two different things:
provider.environmentDoing 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
dotenv.includeto[]will cause the plugin to bypass any interaction withprovider.environmentbecause it will result inenvVarsbeing an empty list:serverless-dotenv-plugin/index.js
Lines 120 to 123 in 2b66c15
neverendingqs commentedon Feb 7, 2021
FYI I have updated the README with this issue and the workaround: #108
RaydelMiranda commentedon Feb 11, 2021
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?
neverendingqs commentedon Feb 14, 2021
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 🙂.
RaydelMiranda commentedon Feb 22, 2021
I agree. I will think some solution for this and let you know here.
docs: updating changes that impact #38.
docs: add FAQ items around new Serverless Framework variables engine. (…
neverendingqs commentedon Feb 27, 2021
serverless>=2.26.0should resolve this issue, although it may cause other breaking issues. Please see the README (relevant changes: #149) for more details.github-actions commentedon Apr 22, 2021
Closed due to inactivity. Please reopen when you get a chance to respond.