Replies: 3 comments 3 replies
-
Hello, this looks like an import error on the build, Next.Js generally comes with .env file processor so separately installing dotenv package isn't necessary. A quick and dirty way to check if your environmental variables are loading as intended is to just console.log it and check what values are being outputted, that gives a solid indication of whether or not .env files are loading or not. If you want to know further, the following link might be of help. (https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables) As for the second error, it seems there was another Github PR that helped clear up the confusion, the following is the link : vercel/next.js#54176. The culprit is most likely the use of "use strict" in your index.js file within the dist directory, as hooks are treated as client side components rather than server side and the fs module is a server side module. Additional link that may be helpful --> vercel/next.js#52566. Lastly, although it's not a big deal and more so depends on your personal preference, utilizing typescript over javascript throughout the entirety of the project is the general sentiment as it tends to be less error prone, but this is entirely up to you. (You can take a look at this link if you would like to gain a better understanding of why typescript is preferred over javascript, https://www.reddit.com/r/typescript/comments/sqswhb/is_it_better_to_just_use_ts_instead_of_js/) I hope this helps, if not, let me know. |
Beta Was this translation helpful? Give feedback.
-
I already checked them with a console.log before sending the question. That is the reason why I told the variables aren't loaded. |
Beta Was this translation helpful? Give feedback.
-
Also have the same issue. Any update on this? Or just how to load env vars from packages? |
Beta Was this translation helpful? Give feedback.
-
Summary
I have a monorepo project with:
Apps: mobile and web.
Packages: hooks, apis, models, etc.
I hooks I have some functions to fetch data. Hooks use some methods from apis.
In apis I'm trying to use some environment variables, but they are not loaded.
I tried with dotenv, but it threw an error.
Attached are images of my config.
What do you think the right way is to handle this case?
Beta Was this translation helpful? Give feedback.
All reactions