#✅ - I have a monorepo which is giving me environment variable.
27 messages · Page 1 of 1 (latest)
FYI the nextjs project is working fine in other repo with the above commands.
👋 are you setting env vars in Amplify Hosting? admittedly a bit confusing, but those will be used during build time. For runtime you can echo these to a dotenv file https://docs.aws.amazon.com/amplify/latest/userguide/ssr-environment-variables.html
Amplify Hosting supports adding environment variables to your application's builds by setting them in the project's configuration in the Amplify console. However, a Next.js server component doesn't have access to those environment variables by default. This behavior is intentional to protect any secrets stored in environment variables that your ...
Thank you for your response. Yes, I have tried added these. It works in the nextjs project but not inside the monorepo.
We have a file called env.mjs where we are doing configurations for the environment variables. It works fine on on vercel though.
Please let me know if you have any possible resolution to this. Thank you!
As per the documentation here I have already done this:
Actually, the build is running fine and deployed as well. However like I mentioned earlier I can't detect the enviroment variables.
Configure the build settings for an app in a monorepo deployed with Amplify Hosting.
Please let me know if you need any more info.
I am checking the cloudwatch logs and the issue is from environment variables being undefined.
Hello @signal ginkgo @grand roost , did you find a solution to this
I have the same issue. The server side has access to the env variables which are prefixed with NEXT_PUBLIC (same validated from the cloud computing logs), however "NEXTAUTH_URL" is not accessible on the server. I am using NX as a build tool and the suggested environment addition method mentioned above.
👋 ah apologies, missed the replies in this thread. You will need to echo the env vars to a dotenv file in your next.js app's directory https://docs.aws.amazon.com/amplify/latest/userguide/environment-variables.html#access-ssr-environment-variables
Environment variables are key-value pairs that you can add to your application's settings to make them available to Amplify Hosting. As a best practice, you can use environment variables to expose application configuration data. All environment variables that you add are encrypted to prevent rogue access.
@grand roost i Have already done this the following way
- env | grep -e NEXT_PUBLIC_SITE_ROOT_DOMAIN -e NEXTAUTH_URL -e NEXTAUTH_SITE -e JWT_SECRET -e NEXT_PUBLIC_API_HOST -e NEXT_PUBLIC_SERVICE_ACCOUNT_TOKEN >> ./apps/acvent/.env.local
I have also tried with adding them to .env.production on the root of the monorepo.
I have also added a cat .env.<whatever> to validate that it is correctly filling the file and it does.
@grand roost do you have a suggestion
can i force an env variable in the hosting server ?
hmm I believe this will get picked up along with the appRoot/build files. let me double-check
P.S. I just created a completely clean project with just the app and it is still giving me the same behavior.
I guess i will open an issue
@dapper granite
Please follow this thread:
https://discord.com/channels/705853757799399426/1127905766209224704
After you fix this one. Please verify if you face this issue:
https://discord.com/channels/705853757799399426/1145985881124130836
For me this issue is still not resolved.
Modify next.config.mjs like it is mentioned in the Missing Env Vars thread and it should work.
How come I don't get any notifications when you mentioned me. Weird.
Hi folks 👋 , apologies for the delayed response here.
For monorepo setups, you will need to prefix the .env.production file with your appRoot to make your environment variables accessible to the server side runtime. This is an example of a buildSpec for a Next.js app within a Nx monorepo:
version: 1
applications:
- frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- env | grep -e DB_HOST -e DB_USER -e DB_PASS >> apps/app/.env.production
- env | grep -e NEXT_PUBLIC_ >> apps/app/.env.production
- npx nx build app
artifacts:
baseDirectory: dist/apps/app/.next
files:
- '**/*'
cache:
paths:
- node_modules/**/*
buildPath: /
appRoot: apps/app
We are working on updating our documentation with the same information.
✅ - I have a monorepo which is giving me environment variable.