Error when deploying in Vercel
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
- Create a new project with
npx next-forge@latest init my-project - Fill all the env variables in .env.local files.
- Check that build command on the root of the project works (
pnpm build) - Create a new repo in GitHub and push the changes.
- Deploy the app project in Vercel. Turbo is detected.
- Change the root of the project and choose
/apps/app - 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):
Screenshot of the error:
Desktop (please complete the following information):
- OS: macOS (latest)
- Browser Chrome
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 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.
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 Ah yes now I remember fixing that recently π
@OsoThevenin I'll ask the Vercel team about that error directly.
@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 π€·ββοΈ
@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 @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
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 π€π» π¦πΊ
Great detective work @Gomah! Yes please I'd love a PR π
:rocket: Issue was released in v2.18.1 :rocket: