-
Allow
@arkenv/nextjsto work with React 18.2.0 and later in the React 18 line, as well as every React 19 release, instead of requiring React 19.2.5. Install it alongside a supported React version, such aspnpm add @arkenv/nextjs react@^18.2.0.
-
When Bun, Next, or Nuxt cannot find an env schema, throw a consistent message that names the expected path /
schemaPathand points tonpx @arkenv/cli@latest init, without embedding a starterenv.tsmodule.Example:
[ArkEnv] Could not find schema file at src/env.ts or env.ts. Please specify 'schemaPath' in ArkEnv options (or run `npx @arkenv/cli@latest init`). -
Strict layout now works with just
client.tsandserver.ts. Omitinternal/shared.tswhen you have nothing to share — shared keys are treated as empty.// env/client.ts + env/server.ts alone is enough export default withArkEnv(nextConfig, { layout: "strict", });
The CLI still scaffolds
shared.tsby default for convenience.
-
Clean up and extend the
keywordsfield of every published package so npm search, aggregators, and LLM-powered package discovery surface ArkEnv for the terms users actually search for.- Remove the misleading
pnpmkeyword fromarkenvand addenv,environment-variables,dotenv,config,standard-schema, and the supported validatorszodandvalibot. - Deduplicate the repeated
arkenvkeyword in@arkenv/vite-plugin. - Give every env-related package a shared baseline (
env,environment-variables,dotenv,config,validation,typesafe,standard-schema) alongside their integration-specific terms. - Add a keyword set to
@arkenv/fumadocs-ui, which previously had none.
- Remove the misleading
-
Automatically validate all required environment variables at build time (e.g. during
next build) inside the config plugin. Missing or malformed environment variables will cause the build to fail immediately with a clear, actionable ArkEnv error, preventing runtime failures. -
Add a
codegenoption towithArkEnvandsetupArkEnvthat disables automaticenv.gen.tsgeneration while keeping build-time environment validation active.Usage:
import { withArkEnv } from "@arkenv/nextjs/config"; import type { NextConfig } from "next"; const nextConfig: NextConfig = {}; export default withArkEnv(nextConfig, { codegen: false });
When
codegenisfalse, provide a manualruntimeEnvmapping in your schema file. The CLI's--no-codegenflag now also skips generatingenv.gen.tsduring scaffolding while still wrappingnext.config.tswithwithArkEnv(nextConfig, { codegen: false }).
-
Introduce a new "Flat" layout mode for
@arkenv/nextjs. The Flat API allows developers to define a flat schema mapping directly to their.envfile structure:import arkenv from "./generated/env.gen"; export const env = arkenv( { DATABASE_URL: "string", NEXT_PUBLIC_API_URL: "string", NODE_ENV: "'development' | 'production' | 'test' = 'development'", CUSTOM_VAR: "string", }, { exposeToClient: ["CUSTOM_VAR"], } );
- Automatically expose
NEXT_PUBLIC_variables and custom keys specified inoptions.exposeToClientto the client. - Secure server-only variables at runtime via a Proxy that throws on unauthorized client access.
- Share
NODE_ENVimplicitly to match standard Next.js build-time inlining behavior. - Rename the configuration
layoutoption value from"simple"to"flat"."simple"is kept as a deprecated runtime alias and will be removed in the next major version. - Update CLI scaffolding to generate the Flat layout by default.
- Update documentation and playground/example apps to use and recommend the Flat layout strategy.
- Automatically expose
-
- Deprecate the legacy nested options overload signature of
createEnvin@arkenv/nextjs. - Add a one-time development-only runtime warning nudge when the legacy nested layout format is detected.
- Add the
--flatflag to@arkenv/clito scaffold the recommended flat layout for Next.js. - BREAKING CHANGE: Drop support for the
@arkenv/cli--simpleflag on Next.js projects; passing it now hard-fails with an error. Runnpx arkenv initinstead (the flat layout is now the default). - Remove the nested layout choice from the Next.js interactive CLI prompt, defaulting to flat.
- Remove the standalone nested layout documentation page and redirect its URL to the FAQ.
- Update the documentation to guide users from the legacy nested layout to the recommended flat layout.
- Deprecate the legacy nested options overload signature of
-
Improve the Next.js developer experience with the following enhancements:
- Expose
setupArkEnvfrom@arkenv/nextjs/configas a non-wrapping alternative towithArkEnv. Use it directly when you are already juggling multiple config wrappers and want to avoid anotherwithX(...)layer. - Remove the
@arkenv/nextjs/registerside-effect import; usewithArkEnvfor the idiomatic wrapper path orsetupArkEnvfor the non-wrapping path. - Support runtime-injectable client-side variables via a new
<ArkEnvScript />component, enabling containerized deployments to configure public client-side variables dynamically without rebuilds. - Fix typesafety for the flat layout so that
envreturns a strongly-typed schema (rather than resolving toany) and server-side variables can be accessed in server components without TypeScript compile errors.
Usage:
// next.config.ts import { withArkEnv } from "@arkenv/nextjs/config"; import type { NextConfig } from "next"; const nextConfig: NextConfig = {}; export default withArkEnv(nextConfig);
// app/layout.tsx import { ArkEnvScript } from "@arkenv/nextjs"; export default function RootLayout({ children }) { return ( <html lang="en"> <body> <ArkEnvScript /> {children} </body> </html> ); }
- Expose
-
Restored strict intersection types (
Record<RequiredKeys, unknown> & Record<string, unknown>) on the Next.jscreateEnvadapter to guarantee compile-time enforcement of required schema keys. Additionally, narrowed the acceptedruntimeEnvrecord value type tostring | undefinedto actively reject invalid configurations.BREAKING CHANGE: If you were using the legacy Next.js
envobject configuration (e.g., passing a nested object toruntimeEnv), or if you were failing to explicitly map all required keys intoruntimeEnv, your build will now fail with a TypeScript error. You must explicitly map all variables referenced in your schema asstring | undefined.Usage:
import { createEnv } from "@arkenv/nextjs"; export const env = createEnv({ client: { NEXT_PUBLIC_API: "string" }, runtimeEnv: { // TypeScript will error if NEXT_PUBLIC_API is missing, // and will also error if you try to pass an object or array. NEXT_PUBLIC_API: process.env.NEXT_PUBLIC_API, }, });
-
Store the active
chokidarwatcher instance onglobalThis.__arkenv_watcher__and close it when configuring a new watcher instance. -
Remove
@deprecatedJSDoc tag fromcreateEnvandarkenvin the main and react-server entries#1139fae4c1f@yamcodesAvoid warning users when they call
createEnvmanually without using the codegen workflow.
-
Correct the hardcoded import path to generated factory in Next.js 3-file strict mode client template. Also export
createEnvas default export (aliased asarkenv) in the generatedenv.gen.tsfile.
-
Generate a tailored
createEnvfactory helper inenv.gen.tswhen using the strict split-schema layout (instead of exporting a rawruntimeEnvobject).This eliminates the need to manually declare or reference the
runtimeEnvobject inside the client schemaclient.tsfile, aligning it closer to the corearkenvexperience of simply callingcreateEnv(schema, options).Example usage in
client.ts:import { createEnv } from "./generated/env.gen"; import { SharedSchema } from "./internal/shared"; export const env = createEnv( { NEXT_PUBLIC_API_URL: "string", }, { extends: [SharedSchema], } );
-
Add support for the strict split schema layout in the Next.js
withArkEnvconfiguration wrapper and update CLI scaffolding instructions:- Add a
layoutoption ("simple" | "strict") towithArkEnvconfiguration, which defaults to auto-detecting the strict layout if split files (env/internal/shared.ts,env/client.ts,env/server.ts) exist. - Implement key extraction from strict client and shared schema files.
- Update CLI next-steps messages to include
withArkEnvwrapping instructions for strict layout nextjs projects.
- Add a
-
Implement Next.js separate files mode, shared entry point, and native extends API
#1084d921785@yamcodesIntroduce dedicated entry points for
@arkenv/nextjs/server,@arkenv/nextjs/client, and@arkenv/nextjs/sharedto prevent metadata leakage and support compile-time bundler-enforced isolation. Add a nativeextendsAPI to merge validated outputs of extended proxies while maintaining proxy-level protections.Also update the CLI
initwizard to support interactive layout selection (Strict 3-file vs Simple 1-file) and--strict/--simpleflags to bypass interactive selection.Example server usage:
import { createEnv } from "@arkenv/nextjs/server"; import { env as clientEnv } from "./env.client"; export const env = createEnv( { DATABASE_URL: "string" }, { extends: [clientEnv] } );
Example client usage:
import { createEnv } from "@arkenv/nextjs/client"; export const env = createEnv( { NEXT_PUBLIC_API_URL: "string" }, { runtimeEnv: { NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL, }, } );
-
Add a Next.js configuration wrapper in
@arkenv/nextjs/configthat automates client-side and shared environment variable destructuring in theruntimeEnvblock:// next.config.ts import { withArkEnv } from "@arkenv/nextjs/config"; import type { NextConfig } from "next"; const nextConfig: NextConfig = { reactStrictMode: true, }; export default withArkEnv(nextConfig);
Key features:
- Zero-Boilerplate Destructuring: Statically extract
clientandsharedkeys from yourenv.tsschema and generate a tailoredcreateEnvfactory ingenerated/env.gen.tsthat pre-fills theruntimeEnvblock. - Development Watcher: Automatically start a lightweight file watcher in development mode to regenerate
generated/env.gen.tson the fly whenenv.tschanges. - Customizable Output: Support custom schema and output paths, enabling developers to write generated files to a dedicated folder (e.g.,
src/generated/env.gen.ts). - Deprecate Direct Exports: Mark direct
createEnvand defaultarkenvexports from the main andreact-serverentry points as deprecated to steer developers toward the new codegen workflow.
Example usage in
env.ts:// env.ts import { createEnv } from "./generated/env.gen"; export const env = createEnv({ client: { NEXT_PUBLIC_API_URL: "string", }, shared: { NODE_ENV: "string", }, });
- Zero-Boilerplate Destructuring: Statically extract
-
Provide ArkType DSL contextual typing for
server,client, andsharedschema values.
-
Client environment variables now correctly infer their validated type instead of resolving to
neverfor non-NEXT_PUBLIC_keys.const env = createEnv({ client: { NEXT_PUBLIC_API_URL: "string", }, runtimeEnv: { NEXT_PUBLIC_API_URL: "https://api.example.com", }, }); env.NEXT_PUBLIC_API_URL; // previously `never`, now `string`