Comments (12)
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.
from serverless-dotenv-plugin.
I agree. I will think some solution for this and let you know here.
from serverless-dotenv-plugin.
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.
from serverless-dotenv-plugin.
I'm getting the same error, any update about this issue?
from serverless-dotenv-plugin.
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.
from serverless-dotenv-plugin.
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.js
we need to replace lines 74
to 79
with the following:
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
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.
Thanks
from serverless-dotenv-plugin.
Thanks for the investigation!
This plugin does two different things:
- 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:
serverless-dotenv-plugin/index.js
Lines 120 to 123 in 2b66c15
from serverless-dotenv-plugin.
FYI I have updated the README with this issue and the workaround: #108
from serverless-dotenv-plugin.
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?
from serverless-dotenv-plugin.
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 🙂.
from serverless-dotenv-plugin.
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.
from serverless-dotenv-plugin.
Closed due to inactivity. Please reopen when you get a chance to respond.
from serverless-dotenv-plugin.
Related Issues (20)
- Plugin should throw on error.
- Release GitHub action workflow only works if there is no branch protection. HOT 1
- Warn when incompatible options are set
- Automatic env file resolution is in reverse order of precedence HOT 7
- Create npmignore file
- Release (next)
- Consider how new variables engine in serverless could improve or impact this plugin HOT 2
- Document differences between Serverless's .env resolution and this plugin HOT 1
- NODE_ENV and stage collides to each other HOT 3
- System environment variables (wrongly) take higher precedence than the .env file HOT 7
- Cannot have parameterized `stage` and `region` HOT 2
- Serverless Framework v3: integrating with the new design
- Can't read multi line env variable - v2.62.0 HOT 2
- Not loading env file from stage param HOT 3
- basePath not getting resolve HOT 3
- Allow ability to set default environment name. HOT 2
- Feature Request: Add `envFile` to configuration.
- Question : setting env var HOT 1
- Fix links in package.json
- Add a pull request template
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serverless-dotenv-plugin.