varlock version
0.5.0, @varlock/nextjs-integration 0.2.3
Problem
Using varlockNextConfigPlugin() crashes any Next.js app that has middleware. Every request returns 500:
⨯ Error [TypeError]: Native module not found: varlock/env
at <unknown> (.next/server/edge-runtime-webpack.js:3:11)
Removing the plugin and using only the @next/env override works fine.
Root cause
The plugin injects patch-next-runtime.js into both the Node.js server runtime and the edge runtime (edge-runtime-webpack.js). That patch file does require('varlock/env'), which works in Node.js but fails in the edge sandbox since it only allows native modules.
The _edgeRuntime parameter in injectVarlockInitIntoWebpackRuntime() is accepted but never used — edge gets the exact same patch as Node.js.
Reproduction
- Next.js 15 project with a
middleware.ts (Clerk, Auth.js, or even a bare NextResponse.next())
- Add the
@next/env override and varlockNextConfigPlugin() per the docs
- Start the dev server, navigate to any page, get a 500
Workaround
Use the @next/env override without the config plugin. Loses leak detection and ENV import support, but env loading and validation work fine.
System Info
Next.js: 15.5.12
Node: v25.2.1
macOS arm64
varlock version
0.5.0, @varlock/nextjs-integration 0.2.3
Problem
Using
varlockNextConfigPlugin()crashes any Next.js app that has middleware. Every request returns 500:Removing the plugin and using only the
@next/envoverride works fine.Root cause
The plugin injects
patch-next-runtime.jsinto both the Node.js server runtime and the edge runtime (edge-runtime-webpack.js). That patch file doesrequire('varlock/env'), which works in Node.js but fails in the edge sandbox since it only allows native modules.The
_edgeRuntimeparameter ininjectVarlockInitIntoWebpackRuntime()is accepted but never used — edge gets the exact same patch as Node.js.Reproduction
middleware.ts(Clerk, Auth.js, or even a bareNextResponse.next())@next/envoverride andvarlockNextConfigPlugin()per the docsWorkaround
Use the
@next/envoverride without the config plugin. Loses leak detection andENVimport support, but env loading and validation work fine.System Info