@arkenv/nextjs
Next.js integration framework for ArkEnv.
@arkenv/nextjs adds Next.js-aware arkenv() entries, build-time
validation, and .arkenv codegen. Setup recipes:
Next.js guide.
Installation
npm install @arkenv/core @arkenv/nextjs arktypepnpm add @arkenv/core @arkenv/nextjs arktypeyarn add @arkenv/core @arkenv/nextjs arktypebun install @arkenv/core @arkenv/nextjs arktypeOr if you use Zod, Valibot, or another Standard Schema validator:
npm install @arkenv/standard @arkenv/nextjs zodpnpm add @arkenv/standard @arkenv/nextjs zodyarn add @arkenv/standard @arkenv/nextjs zodbun install @arkenv/standard @arkenv/nextjs zodSubpaths
| Subpath | Role |
|---|---|
. | Unified arkenv (react-server condition for RSC, default for client/SSR) |
./config | withArkEnv, runCodegen, config types |
./standard | Standard Schema unified entry |
./standard/config | Standard withArkEnv (forces Standard codegen) |
withArkEnv options
import type { NextConfig } from "next";
import { withArkEnv } from "@arkenv/nextjs/config";
const nextConfig: NextConfig = {};
export default withArkEnv(nextConfig);Function-form next.config is supported. ArkEnv awaits the factory and
applies aliases to the resolved object:
import type { NextConfig } from "next";
import { withArkEnv } from "@arkenv/nextjs/config";
export default withArkEnv(async (phase, { defaultConfig }): Promise<NextConfig> => ({
...defaultConfig,
reactStrictMode: phase !== "phase-test",
}));Your app schema imports the generated factory:
import arkenv from "@/.arkenv";
export const env = arkenv({
DATABASE_URL: "string",
NEXT_PUBLIC_API_URL: "string = 'https://api.example.com'",
NODE_ENV: "'development' | 'production' | 'test' = 'development'",
});withArkEnv options
Pass a second argument to change codegen or validation.
| Option | Default | Meaning |
|---|---|---|
codegen | true | Write env.gen.ts |
validate | true | Validate during config/build |
schemaPath | auto | Schema entry path |
outputPath | auto | Generated file path |
standard | false | Standard Schema codegen |
logger | console | Build-time logger |
logLevel | (none) | Minimum log level |
A custom outputPath still imports as @/.arkenv. Next.js aliases the
specifier; codegen keeps .arkenv/index.ts re-exporting that file so
tsc --noEmit matches.
Skip generation during CLI scaffolds with
npx arkenv init --no-codegen.
Programmatic codegen
import { runCodegen } from "@arkenv/nextjs/config";
await runCodegen(schemaPath, outputPath);Standard Schema codegen
Import withArkEnv from @arkenv/nextjs/standard/config to force
Standard Schema-compatible generated imports.
import { withArkEnv } from "@arkenv/nextjs/standard/config";
export default withArkEnv(nextConfig);Client and server keys
Public keys use the NEXT_PUBLIC_ prefix. One schema file plus a runtime
Proxy blocks server-key reads on the client.
For name/type isolation beyond values, see the two-module recipe.