Skip to content

fix(nextjs): handle missing varlock binary on serverless platforms#651

Merged
theoephraim merged 1 commit intomainfrom
fix/nextjs-serverless-binary-exec
Apr 23, 2026
Merged

fix(nextjs): handle missing varlock binary on serverless platforms#651
theoephraim merged 1 commit intomainfrom
fix/nextjs-serverless-binary-exec

Conversation

@theoephraim
Copy link
Copy Markdown
Member

@theoephraim theoephraim commented Apr 23, 2026

Summary

On serverless platforms (Vercel, AWS Lambda), the varlock CLI binary is not available at runtime. When ___next_launcher.cjs loads @next/env (our next-env-compat.js) and calls loadEnvConfig(), execSyncVarlock would crash with "Unable to find varlock executable".

Two issues prevented the catch block from handling this gracefully:

  1. exitOnError: trueexecSyncVarlock called process.exit(1) internally before the error could reach our catch block
  2. showLogsOnError: true — the error was printed to stderr even when it should be silently deferred

Changes

  • Switch to showLogsOnError: false and exitOnError: false so all error handling is in loadEnvConfig's catch block
  • Binary not found + prod: silently return early, defer to the init bundle injected into the webpack/turbopack runtime (platform-injected env vars are already in process.env)
  • Binary not found + dev: clear "varlock not found" install message + exit
  • Validation/other errors: print CLI stdout/stderr ourselves, then process.exit in prod

Fixes #584

Test plan

  • Local serverless simulation (stripped PATH + hidden binary) — loadEnvConfig returns cleanly with no stderr
  • next build on example app — works normally
  • Typecheck passes
  • Deploy to Vercel with Next.js 16.2+ — confirm no crash or confusing error output
  • next dev without varlock installed — confirm clear error message

Two issues caused "Cannot find module 'varlock'" and "Unable to find
varlock executable" errors on Vercel with recent Next.js versions:

1. Vercel's builder now always uses the bundled server path, which
   inlines @next/env so @vercel/nft no longer traces its dependencies.
   Fix: split tsup config so next-env-compat bundles varlock modules
   directly (noExternal), eliminating external require('varlock') calls.

2. The varlock CLI binary is not available at runtime on serverless
   platforms. Fix: call execSyncVarlock with exitOnError:false and
   handle errors in loadEnvConfig's catch block — when the binary is
   not found in production, defer to the init bundle injected into the
   webpack/turbopack runtime.

Also removes stale exports (varlock-env-inline, edge-env).

Fixes #584
@theoephraim theoephraim force-pushed the fix/nextjs-serverless-binary-exec branch from a90ef35 to f7cd494 Compare April 23, 2026 17:54
@bumpy-bot
Copy link
Copy Markdown
Collaborator

bumpy-frog

The changes in this PR will be included in the next version bump.

patch Patch releases

  • @varlock/nextjs-integration 0.3.5 → 0.3.6

Bump files in this PR

Click here if you want to add another bump file to this PR


This comment is maintained by bumpy.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 23, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@varlock/nextjs-integration@651

commit: f7cd494

@theoephraim theoephraim merged commit 8ff9336 into main Apr 23, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Cannot find module 'varlock', on Vercel

2 participants