Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

561
Visualizações
"TypeError: Cannot read property 'config' of undefined" in dotenv

I'm trying to get access to my .env file via dotenv module, but I'm getting the below error

dotenv.config();
       ^
TypeError: Cannot read property 'config' of undefined

I have dotenv installed in node_modules and package.json, my .env file is in the root folder, and I think everything is written correctly, but it doesn't work for some reason. I have tried reinstalling the module, didn't help

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

try the following :

require('dotenv').config({path: __dirname + '/.env'})

In Typescript

import * as dotenv from 'dotenv'
dotenv.config({path: __dirname + '/.env'})
over 4 years ago · Santiago Trujillo Relatório

0

Another way to fix this is to enable esModuleInterop in Typescript compiler options.

Open tsconfig.json and add this line:

"esModuleInterop": true,

so you can import it like this:

import hello from 'hello-world';
over 4 years ago · Santiago Trujillo Relatório

0

try this:

 const path = require('path')
 require('dotenv').config({ path: path.resolve(__dirname, '../.env') })
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda