V
V
Vann Damm2020-01-20 15:40:26
Node.js
Vann Damm, 2020-01-20 15:40:26

When building, dotenv-webpack throws undefiend when I access its .definitions[process.env.NODE_ENV] property?

Code for pulling .env parameters.
const DotEnv = require('dotenv-webpack');
const path = require('path');
const {rootPath}= require('./paths');
let envParams = null;
const someEnvCovert = () => {
if (!envParams) {
envParams = new DotEnv({
path: path.resolve(rootPath,'.frontend.env.dev.example'),
safe: path.resolve(rootPath,'. frontend.env.prod.example'),
defaults: false,
systemvars: false,
});
}
};
const getParam = (param)=>{
someEnvCovert();
return envParams.definition[`process.env.${param}`].slice(1).slice(0, -1) || false;
};
const getParamAsNumber = (param)=>(Number(getParam(param)));
const getParamAsBoolean = (param)=>(getParam(param)==='true');
module.exports = {
getParam,
getParamAsBoolean,
getParamAsNumber,
isProduction: getParam('NODE_ENV') === 'production',
};
Gives such an error, what can be?
5e259faa62aa7520215909.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question