fix(nextjs): handle missing varlock binary on serverless platforms#651
Merged
theoephraim merged 1 commit intomainfrom Apr 23, 2026
Merged
fix(nextjs): handle missing varlock binary on serverless platforms#651theoephraim merged 1 commit intomainfrom
theoephraim merged 1 commit intomainfrom
Conversation
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
a90ef35 to
f7cd494
Compare
Collaborator
|
The changes in this PR will be included in the next version bump.
|
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
On serverless platforms (Vercel, AWS Lambda), the varlock CLI binary is not available at runtime. When
___next_launcher.cjsloads@next/env(ournext-env-compat.js) and callsloadEnvConfig(),execSyncVarlockwould crash with "Unable to find varlock executable".Two issues prevented the catch block from handling this gracefully:
exitOnError: true—execSyncVarlockcalledprocess.exit(1)internally before the error could reach our catch blockshowLogsOnError: true— the error was printed to stderr even when it should be silently deferredChanges
showLogsOnError: falseandexitOnError: falseso all error handling is inloadEnvConfig's catch blockprocess.env)process.exitin prodFixes #584
Test plan
loadEnvConfigreturns cleanly with no stderrnext buildon example app — works normallynext devwithout varlock installed — confirm clear error message