I tried using require('dotenv').config() in my javascript file and my package.json, I have dotenv as my dependency, I am able to check my environment variable however, when it comes to loading my javascript page, it throws an error: "Uncaught ReferenceError: require is not defined". If I remove require('dotenv').config() my page loads perfectly with javascript however, when I add require('dotenv').config() this again, it throws the subject line error. Can someone please help me with the solution, thanks in advance.
Asked
Active
Viewed 240 times
0
-
Do you run this script in the browser? – Konrad Oct 20 '22 at 17:32
-
I run it in node. browser would mean client side? – DevelopingCoder Oct 20 '22 at 17:38
-
1https://stackoverflow.com/questions/65752833/referenceerror-require-is-not-defined-using-requiredotenv-config – Andy Oct 20 '22 at 17:49
-
Thanks Andy, I checked this post though, I do not have type = module in .json package. Not sure, what else is causing the error :( – DevelopingCoder Oct 20 '22 at 18:01
-
I think this could be relaed to this problem https://stackoverflow.com/a/74134178/2743774 – Franco Aguilera Oct 20 '22 at 18:44
-
similar, tried the import solution as well, doesn't work – DevelopingCoder Oct 20 '22 at 19:19