[英]aws amplify - process.env.API_KEY is undefined
I add to amplify build setting:我添加以放大构建设置:
I also add to amplify.yml in the code我还在代码中添加到 amplify.yml
version: 0.1
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run export
**- REACT_APP_ENV_API=${REACT_APP_ENV_API}**
artifacts:
baseDirectory: .next
files:
- '**/*'
cache:
paths:
- node_modules/**/*
I add to the amplify env vars my react env var here:我在这里将我的反应环境变量添加到放大环境变量中:
and still I get undefined when I trying to use process.env.REACT_APP_ENV_API.当我尝试使用 process.env.REACT_APP_ENV_API 时,我仍然不确定。
You're missing export
:你缺少export
:
- export REACT_APP_ENV_API=${REACT_APP_ENV_API}
Also, as per Julio's comments, if you're using Next.js, do make sure you're doing as documented for exposing env vars to the browser: https://nextjs.org/docs/basic-features/environment-variables#exposing-environment-variables-to-the-browser此外,根据 Julio 的评论,如果您使用的是 Next.js,请确保您按照文档向浏览器公开环境变量: https://nextjs.org/docs/basic-features/environment-variables#exposing -环境变量到浏览器
I got it working by first adding the environment variables to the AWS Amplify console via App Settings > Environment Variables.我首先通过 App Settings > Environment Variables 将环境变量添加到 AWS Amplify 控制台来让它工作。
Then I went to App Settings > Build Settings and modified the amplify.yml
config file to include the variable definitions.然后我转到 App Settings > Build Settings 并修改amplify.yml
配置文件以包含变量定义。
Eg:例如:
version: 1
frontend:
phases:
preBuild:
commands:
- yarn install
build:
commands:
- echo "GITHUB_CLIENT_ID=$GITHUB_CLIENT_ID" >> .env
- echo "GITHUB_CLIENT_SECRET=$GITHUB_CLIENT_SECRET" >> .env
- echo "NEXTAUTH_URL=$NEXTAUTH_URL" >> .env
- echo "NEXTAUTH_SECRET=$NEXTAUTH_SECRET" >> .env
- yarn run build
artifacts:
baseDirectory: .next
files:
- "**/*"
cache:
paths:
- node_modules/**/*
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.