haydenbleasel / next-forge

Production-grade Turborepo template for Next.js apps.
https://www.next-forge.com/
MIT License
3.83k stars 296 forks source link

Error when deploying in Vercel #247

Open OsoThevenin opened 4 days ago

OsoThevenin commented 4 days ago

Describe the bug I am deploying a clean version of next-forge in Vercel, and it fails due to env variables wrongly configured. The latest commit in my git is the result of running the init script.

next-forge version I am using version 2.14.15

To Reproduce

  1. Create a new project with npx next-forge@latest init my-project
  2. Fill all the env variables in .env.local files.
  3. Check that build command on the root of the project works (pnpm build)
  4. Create a new repo in GitHub and push the changes.
  5. Deploy the app project in Vercel. Turbo is detected.
  6. Change the root of the project and choose /apps/app
  7. Add the env variables and deploy

I also tried to create a new project through the Vercel Marketplace but got the same result. Also tried to modify the build commands (see screenshot) because the default was turbo build Edit: Also executed the vercel link to try to discard and tried to made NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL optional in case it was failing due to the first build.

Expected behavior Expected to compile successfully

Screenshots Screenshot of the project configuration (app):

image

Screenshot of the error:

image

Desktop (please complete the following information):

OsoThevenin commented 4 days ago

I managed to solve the issue by manually adding the env variable NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URLin Vercel. How does exactly Vercel add this env variable? Because after successfully building the app project for the first time, I tried to remove the env variable and the build failed due to the same error.

Also, I want to point out that had to undo the command pnpm build and use the turbo build one (first time working with turbo 😅)

I can give a hand improving the documentation if it's the case. Thanks for your work 🫡

haydenbleasel commented 4 days ago

@OsoThevenin It should be added by Vercel on deploy: https://vercel.com/docs/projects/environment-variables/framework-environment-variables#NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL. Weird that it's not. I'll look into it.

coderreco commented 4 days ago

Also experiencing this issue and cannot for the life of me figure out why. Currently it is not throwing the following:

app:build: ❌ Invalid environment variables: {
app:build:   CLERK_SECRET_KEY: [ 'Required' ],
app:build:   RESEND_AUDIENCE_ID: [ 'Required' ],
app:build:   FLAGS_SECRET: [ 'Required' ]
app:build: }

Edit: Figured it out! Was not reading the warnings in the logs underneath the errors—oops. They were not in the turbo.json file, but I can see that the most recent code does include them.

Thanks for the great work!

haydenbleasel commented 3 days ago

@coderreco Ah yes now I remember fixing that recently 😂

@OsoThevenin I'll ask the Vercel team about that error directly.

coderreco commented 3 days ago

@coderreco Ah yes now I remember fixing that recently 😂

@OsoThevenin I'll ask the Vercel team about that error directly.

I actually did also experience the same error as originally reported. If I delete the NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL it will throw an error and stop the build. Have to add manually. Confirmed on both app and web 🤷‍♂️

haydenbleasel commented 2 days ago

@OsoThevenin @coderreco are you folks pushing "production" Vercel deploys? I.e. is the branch you're pushing marked as the production branch in Vercel deployments?

OsoThevenin commented 2 days ago

@OsoThevenin @coderreco are you folks pushing "production" Vercel deploys? I.e. is the branch you're pushing marked as the production branch in Vercel deployments?

Yes, that's my case