Deploy through github workflow fails only for custom env

I’ve followed this guide to deploy any commit to my new custom env test.
Here is my workflow:

name: Vercel Test Deployment
on:
push:
branches-ignore:
- main
jobs:
Deploy-Test:
runs-on: ubuntu-latest
environment: Preview
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
STRIPE_SECRET_KEY: ${{ secrets.STRIPE_SECRET_KEY }}
STRIPE_WEBHOOK_SECRET: ${{ secrets.STRIPE_WEBHOOK_SECRET }}
NEXT_TELEMETRY_DISABLED: 1
ENABLE_EXPERIMENTAL_COREPACK: 1
NODE_OPTIONS: '--max-old-space-size=8192'
REDIS_URL: ${{ secrets.REDIS_URL }}
SKIP_POSTBUILD: true
steps:
- uses: actions/checkout@v2
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Pull Vercel Environment Information
run: vercel pull --yes --token=${{ secrets.VERCEL_TOKEN }}
- name: Build Project Artifacts
run: vercel build --environment=test --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
run: vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}

Running this workflow, I get a build error:

Generating static pages (0/38) ...

[232](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:233)TypeError: Invalid URL

[233](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:234)at t.default (.next/server/chunks/5375.js:3:24386)

[234](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:235)at 34790 (.next/server/chunks/5375.js:3:107104)

[235](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:236)at t (.next/server/webpack-runtime.js:1:128)

[236](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:237)at 8364 (.next/server/chunks/3528.js:1:1178)

[237](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:238)at t (.next/server/webpack-runtime.js:1:128)

[238](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:239)at 44740 (.next/server/chunks/3528.js:1:12062)

[239](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:240)at Object.t [as require] (.next/server/webpack-runtime.js:1:128) {

[240](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:241)code: 'ERR_INVALID_URL',

[241](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:242)input: ''

[242](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:243)}

[243](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:244)Error occurred prerendering page "/_not-found". Read more: https://nextjs.org/docs/messages/prerender-error

[244](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:245)TypeError: Invalid URL

[245](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:246)at new URL (node:internal/url:806:29)

[246](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:247)at t.default (/home/runner/work/haven-app/haven-app/.next/server/chunks/5375.js:3:24386)

[247](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:248)at 34790 (/home/runner/work/haven-app/haven-app/.next/server/chunks/5375.js:3:107104)

[248](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:249)at t (/home/runner/work/haven-app/haven-app/.next/server/webpack-runtime.js:1:128)

[249](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:250)at 8364 (/home/runner/work/haven-app/haven-app/.next/server/chunks/3528.js:1:1178)

[250](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:251)at t (/home/runner/work/haven-app/haven-app/.next/server/webpack-runtime.js:1:128)

[251](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:252)at 44740 (/home/runner/work/haven-app/haven-app/.next/server/chunks/3528.js:1:12062)

[252](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:253)at Object.t [as require] (/home/runner/work/haven-app/haven-app/.next/server/webpack-runtime.js:1:128)

[253](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:254)at require (/home/runner/work/haven-app/haven-app/node_modules/.pnpm/next@15.3.0_@babel+core@7.27.1_@opentelemetry+api@1.9.0_@playwright+test@1.52.0_react-d_dd4646987bfb2246c23c65d1b77cd876/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:140:10304)

[254](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:255)at u (/home/runner/work/haven-app/haven-app/node_modules/.pnpm/next@15.3.0_@babel+core@7.27.1_@opentelemetry+api@1.9.0_@playwright+test@1.52.0_react-d_dd4646987bfb2246c23c65d1b77cd876/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:92:646)

[255](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:256)Export encountered an error on /_not-found/page: /_not-found, exiting the build.

[256](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:257)⨯ Next.js build worker exited with code: 1 and signal: null

[257](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:258) ELIFECYCLE Command failed with exit code 1.

[258](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:259)Error: Command "pnpm run build" exited with 1

[259](https://github.com/Haven-Refugees/haven-app/actions/runs/14972673903/job/42057074123#step:5:260)Error: Process completed with exit code 1.

Locally build works fine, and even more strangely, If I set the deployment workflow destination to ‘preview’ env (and not my custom env) everything works just fine!! (:face_with_raised_eyebrow: )

Any idea what can fix it?

Solved by adding NEXTAUTH_URL to the env vars.
For some reason in the custom env it is not exposed automatically, as in the preview/production envs

I see an environment option set on the build command, but it’s not a valid option. That should be moved up to the pull command to make sure the right variables and settings are used.

It looks like the vercel build and vercel deploy commands are also missing the target option. What happens when you set that and try again?

Sorry I’ve shared abovemy old workflow code, here is my current one (which is working):

  Deploy-Test:
    runs-on: ubuntu-latest
    environment: Preview
    env:
      VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
      VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
      STRIPE_SECRET_KEY: ${{ secrets.STRIPE_SECRET_KEY }}
      STRIPE_WEBHOOK_SECRET: ${{ secrets.STRIPE_WEBHOOK_SECRET }}
      NEXT_TELEMETRY_DISABLED: 1
      ENABLE_EXPERIMENTAL_COREPACK: 1
      NODE_OPTIONS: '--max-old-space-size=8192'
      REDIS_URL: ${{ secrets.REDIS_URL }}
      NEXTAUTH_URL: ***
      SKIP_POSTBUILD: true
    steps:
      - uses: actions/checkout@v2
      - name: Install Vercel CLI
        run: npm install --global vercel@latest
      - name: Pull Vercel Environment Information
        run: vercel pull --yes --environment=test --token=${{ secrets.VERCEL_TOKEN }}
      - name: Build Project Artifacts
        run: vercel build --target=test --token=${{ secrets.VERCEL_TOKEN }}
      - name: Deploy Project Artifacts to Vercel
        run: vercel deploy --target=test --prebuilt --token=${{ secrets.VERCEL_TOKEN }}
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.