Comments (12)
I think I have a similar issue.
I run my serverless code inside of a subfolder of my larger project and the .env.${NODE_ENV} file is at the root. So in my server package I have this script:
NODE_ENV=development serverless deploy
Within my serverless.yml with the dotenv plugin I have:
custom:
dotenv:
path: ../../.env.${env:NODE_ENV}
But that doesn't work. The system doesn't load any of the env vars in that file.
If I hard code it like:
custom:
dotenv:
path: ../../.env.development
It works fine.
Is it possible to use environment variables in the setup of dotenv before it loads them from the file? I hope that makes a bit of sense. @SarasArya I hope this is the same as what you're trying to accomplish.
from serverless-dotenv-plugin.
Hi SarasArya, I'm having trouble wrapping my head around what the issue is. Is there any way you can point me to an example project or record a screencast, or something more visual?
from serverless-dotenv-plugin.
@bryankennedy Were you able to find a solution to this? I'm in the same boat.
from serverless-dotenv-plugin.
Unfortunately, I'm just working around this by having multiple .env files for now. This allows me to just directly reference the .env file without trying to go outside of the containing directory. Not ideal, but it's all that I could get working for now.
from serverless-dotenv-plugin.
@bryankennedy I haven't looked at the code in a long time but if you take a look at the source code you see that .env.[NODE_ENV]
will get loaded automatically. There's no need to include that in your config. Let me know if I'm missing something.
from serverless-dotenv-plugin.
Hey @bryankennedy My issue was the same. Also, there should be an option on where is my .env file. It assumes it's in my root of the service. But what if it's not. What if it's in the root of the project. Hence the readFrom
option
from serverless-dotenv-plugin.
@colynb It's just this line here: https://github.com/colynb/serverless-dotenv-plugin/blob/master/index.js#L33
Since it's just returning the path, it doesn't support '.production', '.development', etc. It needs the fully resolved path + name. If this was updated to be the same as the next return, only with path prepended should be all good.
from serverless-dotenv-plugin.
Since it's just returning the path, it doesn't support '.production', '.development', etc. It needs the fully resolved path + name. If this was updated to be the same as the next return, only with path prepended should be all good.
@webchaz I see. Because the path is custom, you lose the ability to use the environment. If a lot of people are using the path config option to set the full path instead of the base path, I make an update as you suggested, it would be a breaking change I think. I might have to include another option like "basePath".
from serverless-dotenv-plugin.
@colynb that would be great or maybe a new major version to keep the api the same - totally up to you, either way would be awesome!
from serverless-dotenv-plugin.
@colynb This should handle it:
resolveEnvFileName(env) {
const configPath = (this.config && this.config.path) ? this.config.path : ''
return fs.existsSync(`${configPath}.env.${env}`) ? configPath + '.env.' + env : '.env'
}
from serverless-dotenv-plugin.
Ok, I just published a new version, 2.1.0. It includes a basePath
option now.
from serverless-dotenv-plugin.
@colynb Awesome, just tried it out, works great - thank you!
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.