英文:
Dotenv file not giving variables NextJS
问题
Im trying nextjs and i have encountered a problem. My path is like this
In connectToMongo my variable is coming
But when in Main/index.tsx
my process.env is empty object
I also have problem when i push files to github .env file pushing too but i added it to .gitignore
My key is right, but dotenv is not seeing it
I tried to add
dotenv.config({path: '.env'})
But it not helped me
英文:
Im trying nextjs and i have encountered a problem. My path is like this
In connectToMongo my variable is coming
But when in Main/index.tsx
my process.env is empty object
I also have problem when i push files to github .env file pushing too but i added it to .gitignore
My key is right, but dotenv is not seeing it
I tried to add
dotenv.config({path: '.env'})
But it not helped me
答案1
得分: 2
当您使用Next.js时,您不需要dotenv
包。Next.js会自动从.env
或.env.local
文件中导入环境变量。而且,只有带有NEXT_PUBLIC
前缀的变量才会在客户端上可用。
英文:
When you are using Next.js, you don't need dotenv
package. Next.js automatically imports the environment variables from .env
or .env.local
files. Also, only the variables with NEXT_PUBLIC
prefix will be available on client side.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论