#✅ - I have a monorepo which is giving me environment variable.

27 messages · Page 1 of 1 (latest)

signal ginkgo
#

I have a monorepo which uses the pnpm environment. I have added the environment variables in the UI.

However, they are not being detected. Next auth is throwing error because it can't find he environment variable.

signal ginkgo
#

FYI the nextjs project is working fine in other repo with the above commands.

signal ginkgo
#

My problem is similar to this one:

grand roost
#

👋 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

signal ginkgo
#

Please let me know if you have any possible resolution to this. Thank you!

signal ginkgo
#

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.

#

Please let me know if you need any more info.

signal ginkgo
#

I am checking the cloudwatch logs and the issue is from environment variables being undefined.

dapper granite
#

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.

grand roost
# dapper granite Hello <@1047748296686440488> <@143912968529117185> , did you find a solution to ...

👋 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

dapper granite
#

@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 ?

grand roost
#

hmm I believe this will get picked up along with the appRoot/build files. let me double-check

dapper granite
#

P.S. I just created a completely clean project with just the app and it is still giving me the same behavior.

dapper granite
#

I guess i will open an issue

signal ginkgo
#

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.

full ridge
#

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.

exotic hillBOT
#

✅ - I have a monorepo which is giving me environment variable.