-
-
Notifications
You must be signed in to change notification settings - Fork 861
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
Using with ES6 modules #133
Comments
I see that there were a few other issues for this in the past, but I didn't see that a solution was ever reached? I know preloading the module was recommended, but unfortunately that's not an option in this case. I'd be happy to submit a PR for this if you'd like. |
hey @jsonmaur you can set options using the preload script. You can pass in the options via the a arg on the command. node -r dotenv/config your_script.js dotenv_config_silent=true |
closing this, if this does not work for you let me know |
I faced this problem as well, and I couldn't figure out how to use node preload script because I was running index.jsimport _ from './env'
import hello from './hello' env.jsimport dotenv from 'dotenv'
dotenv.config({ silent: true }) Hope this is helpful for anyone who faces this issue. |
Thanks @ngzhian this fix worked for me! |
import './env'; Should do it if you don't want to pollute the scope |
I doesn't work for me with babel-node. |
@morajabi Have you found a workaround for |
@sa-adebayo Yes and the solution is simply don't use node --require 'dotenv/config' --require 'babel-register' now you don't need to require or import |
How to use dotenv with stenciljs ? |
This worked for me:
Keep in mind that it won't work if you put the |
I was able to get babel-node --require node_modules/dotenv/config script The above call works as an NPM script with To run it from the command-line with node_modules/.bin/babel-node --require node_modules/dotenv/config script Although adding babel-node --require node_modules/dotenv/config script these opts are in process.argv // script.js
console.log(process.argv); // [ 'node', 'full/path/to/script', 'these', 'opts', 'are', 'in', 'process.argv' ] Note: This was tested with |
I'm currently using this plugin of babel and it's working in the same way The difference is that I don't need to require and load it in my entry points. /* .babelrc */
{
"presets": ["env"],
"plugins": ["inline-dotenv"]
} Hope my 2 cents help. |
Trying to do this in a TypeScript environment:
import dotenv from 'dotenv'
dotenv.config({ silent: true }) After installing
import * as dotenv from 'dotenv'
dotenv.config() |
I am new to Express with TypeScript, but nothing of this works for me. I am getting an error |
Compact: (await import('dotenv')).config() |
There's many environments that doesn't support top-level awaits. |
Please check here: https://stackoverflow.com/a/72847459/12002600 |
|
Not Worked |
What error you get after doing this @AbdulRehmanConqueror |
isn't silent deprecated? |
silent option was removed in v3. I guess they don't have a warning when silent is used. |
whoops i'm sorry for my mistakes |
In the case of using ES6 modules via
import
, configuring dotenv in the base file doesn't set the environment vars in sub-modules. For example:index.js
hello.js
This is because babel compiles the above as
It works if I do
import 'dotenv/config'
instead, but then I can't specify thesilent
flag, so it throws an error if.env
doesn't exist (for example, if running in production). I think a simple solution would be to allow something such asimport 'dotenv/register'
for a one-line, silent setup of the variables.The text was updated successfully, but these errors were encountered: