Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

573
Views
"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 answers
Answer question

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 Report

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 Report

0

try this:

 const path = require('path')
 require('dotenv').config({ path: path.resolve(__dirname, '../.env') })
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!