next-forge icon indicating copy to clipboard operation
next-forge copied to clipboard

Error when deploying in Vercel

Open OsoThevenin opened this issue 1 year ago β€’ 8 comments

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):

  • OS: macOS (latest)
  • Browser Chrome

OsoThevenin avatar Nov 15 '24 13:11 OsoThevenin

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 🫑

OsoThevenin avatar Nov 15 '24 16:11 OsoThevenin

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

haydenbleasel avatar Nov 15 '24 17:11 haydenbleasel

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!

coderreco avatar Nov 15 '24 19:11 coderreco

@coderreco Ah yes now I remember fixing that recently πŸ˜‚

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

haydenbleasel avatar Nov 16 '24 10:11 haydenbleasel

@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 πŸ€·β€β™‚οΈ

coderreco avatar Nov 16 '24 10:11 coderreco

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

haydenbleasel avatar Nov 16 '24 23:11 haydenbleasel

@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

OsoThevenin avatar Nov 17 '24 09:11 OsoThevenin

I faced the same issue, and I think it's due to the zod validation in the env package, which is incorrect:

// Added by Vercel
NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL: z.string().min(1).url()

The NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL variable is a bit misleading (perhaps Vercel should have named it NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_DOMAIN ?) as it returns the domain without the protocol, so the .url() check from zod is likely to fail.

I fixed it by removing .url() and adding a prefix helper where NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL is called ✌🏻

Happy to submit a PR & thank you for this awesome template @haydenbleasel 🀚🏻 πŸ‡¦πŸ‡Ί

Gomah avatar Nov 21 '24 10:11 Gomah

Great detective work @Gomah! Yes please I'd love a PR πŸ™

haydenbleasel avatar Nov 21 '24 15:11 haydenbleasel

:rocket: Issue was released in v2.18.1 :rocket:

github-actions[bot] avatar Nov 25 '24 15:11 github-actions[bot]