[英]Vercel next.js environment variable not working
I'm using google maps in a Next.js project and everything's working locally.我在 Next.js 项目中使用谷歌地图,一切都在本地工作。 The google maps secret key is being stored in next.config.js which I access in the code through process.env.NEXT_PUBLIC_GOOGLEMAPS
谷歌地图密钥存储在 next.config.js 中,我通过 process.env.NEXT_PUBLIC_GOOGLEMAPS 在代码中访问它
When I deployed the project to Vercel, I didn't include next.js.config for security reasons.当我将项目部署到 Vercel 时,出于安全原因,我没有包含 next.js.config。 So I added the key under Settings -> Environment Variables
所以我在 Settings -> Environment Variables 下添加了密钥
However, the environment variable is not working in production.但是,环境变量在生产中不起作用。 When I console log process.env.NEXT_PUBLIC_GOOGLEMAPS, I get undefined
当我控制台记录 process.env.NEXT_PUBLIC_GOOGLEMAPS 时,我得到未定义
What could be causing this issue and how can I fix it?什么可能导致此问题,我该如何解决? Thanks
谢谢
This is how I got my setup to work...这就是我让我的设置工作的方式......
env.local
file for local dev key.env.local
文件。 Add .env.local.*
to.gitignore This file has my key/value pair like so:.env.local.*
添加到 .gitignore这个文件有我的键/值对,如下所示:
1 NEXT_PUBLIC_G_KEY=AFLkefjlkwblahblahblah
env
space:env
文件,它在环境空间中也有这个键:
env: { NEXT_PUBLIC_G_KEY: process.env.NEXT_PUBLIC_G_KEY }
(process.env works out of the box according to the docs )env: { NEXT_PUBLIC_G_KEY: process.env.NEXT_PUBLIC_G_KEY }
(process.env 根据文档开箱即用)
$> yarn now secret add MyAppName_PRoD_G_KEY AFLkefjlkwblahblahblah
I have the similar problem.我有类似的问题。 In my env variable list of Vercel dashboard I have used vercel url value but it is picking up the old value of url.
在 Vercel 仪表板的 env 变量列表中,我使用了 vercel url 值,但它正在使用 url 的旧值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.