Closed
Description
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
import dotenv from 'dotenv'
dotenv.config({ silent: true })
import hello from './hello'
hello.js
console.log(process.env) /* this doesn't have the environment vars in it */
This is because babel compiles the above as
var dotenv = require('dotenv')
var hello = require('./hello')
dotenv.config({ silent: true })
It works if I do import 'dotenv/config'
instead, but then I can't specify the silent
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 as import 'dotenv/register'
for a one-line, silent setup of the variables.
Metadata
Metadata
Assignees
Labels
No labels