EN
Express.js - dotenv require error
1
answers
0
points
When I try to import dotenv using:
require('dotenv').config()
I get the following error:
file:///C:/some_path/index.js:9
require('dotenv').config();
^
ReferenceError: require is not defined
at file:///C:/some_path
Can someone help me to fix this?
1 answer
0
points
There are two solutions for this problem:
1. Remove "type": "module"
from the package.json file
2. If you installed esm (es modules) and you are using import
keyword instead of require
to import packages use the following commands:
- Import dotenv
import dotenv from 'dotenv';
- Then use:
dotenv.config();
0 comments
Add comment