Dotenv 文件未提供变量给 NextJS。

huangapple go评论69阅读模式
英文:

Dotenv file not giving variables NextJS

问题

Im trying nextjs and i have encountered a problem. My path is like this

Dotenv 文件未提供变量给 NextJS。

In connectToMongo my variable is coming

Dotenv 文件未提供变量给 NextJS。

But when in Main/index.tsx my process.env is empty object

Dotenv 文件未提供变量给 NextJS。

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

Dotenv 文件未提供变量给 NextJS。

In connectToMongo my variable is coming

Dotenv 文件未提供变量给 NextJS。

But when in Main/index.tsx my process.env is empty object

Dotenv 文件未提供变量给 NextJS。

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.

huangapple
  • 本文由 发表于 2023年7月23日 20:51:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76748336.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定