I have set a helper to access my process.env as below:
export const env = (key: string, def: any = null): string|any => {
console.log(process.env["APP_ENV"], process.env[key], key === "APP_ENV")
// @ts-ignore
if ( process.env[key] instanceof String && process.env[key].length) {
return process.env[key]
}
return def
}
This is injected to all my modules with plugins:
plugins: [
new Dotenv(),
new webpack.ProvidePlugin({
env: ['./plugins/config_helper', 'env'],
})
]
when I access it as env("APP_ENV") I get a baffling result from my debug prints.
develop undefined true
Can someone explain this behavior? More specifically, why does process.env produce undefined when I access it via a variable?