dotenv icon indicating copy to clipboard operation
dotenv copied to clipboard

2.0 Error: Dynamic require of "fs" is not supported

Open JoshuaGerke opened this issue 1 year ago • 1 comments

Error on using JS Module v2 and Dotenv

import 'dotenv/config';

[22:18:45][Error] Error: Dynamic require of "fs" is not supported at file:///C:/Users/Comma/Documents/ProjectReborn/server/altv/resources/gamemode/server/startup.js:39:9 at node_modules/dotenv/lib/main.js (file:///C:/Users/Comma/Documents/ProjectReborn/server/altv/resources/gamemode/server/startup.js:119:15) at __require2 (file:///C:/Users/Comma/Documents/ProjectReborn/server/altv/resources/gamemode/server/startup.js:42:50) at file:///C:/Users/Comma/Documents/ProjectReborn/server/altv/resources/gamemode/server/startup.js:424:3 at file:///C:/Users/Comma/Documents/ProjectReborn/server/altv/resources/gamemode/server/startup.js:431:3

JoshuaGerke avatar May 06 '24 20:05 JoshuaGerke

if you are using dotenvx in an es module environment, shouldn't you be loading it as the following?

import dotenv from 'dotenv';
dotenv.config();

motdotla avatar Dec 03 '24 17:12 motdotla