@pixelmatters/validate-env weekly downloads statistics
By pixelmatters (2 listings) · npm · Webpack plugins
Validate environment variables against a Standard Schema when Vite, webpack, Rspack, Rsbuild or Next.js starts
@pixelmatters/validate-env has 257 recorded weekly downloads on npm, a change of -57.6% over the past 7 days, ranking #2423 of 3,247 tracked listings.
About @pixelmatters/validate-env
@pixelmatters/validate-env
Validate environment variables against a Standard Schema such as Zod, Valibot, or ArkType before your dev server or build starts. Use it in Vite, webpack, Rspack, Rsbuild, Next.js, or Node scripts to stop startup on missing or invalid values.
Highlights
- Fail before startup. Missing or invalid variables print one line each and exit with code 1, before your build or dev server starts.
- Bring your own schema. Any validator that implements Standard Schema works, such as Zod, Valibot or ArkType, synchronous or async.
- Fits each bundler. Each bundler's subpath checks what that bundler loads, from Vite to Next.js, without adding a bundler dependency.
- Run without a bundler. Import the package root in any Node script to validate a record, filter it by prefix and format the issues.
Install
pnpm add -D @pixelmatters/validate-env
Install a Standard Schema library such as zod if your project does not have
one yet. All bundler peer dependencies are optional, so you only need the
bundler your project uses. See Requirements for supported
versions and CommonJS setup.
Quick start
// vite.config.ts
import { defineConfig } from 'vite'
import * as z from 'zod'
import { validateEnv } from '@pixelmatters/validate-env/vite'
const envSchema = z.object({
VITE_API_URL: z.url(),
})
export default defineConfig({
plugins: [validateEnv(envSchema)],
})
When Vite resolves your config, the plugin validates the VITE_ variables
loaded from your .env* files and process environment. If any variable is
missing or invalid, it prints one line per issue and exits with code 1.
========================================
❌ Environment variables issues:
VITE_API_URL: Invalid input: expected string, received undefined
========================================
Write your schema
import * as z from 'zod'
const envSchema = z.object({
VITE_API_URL: z.url(),
VITE_TIMEOUT_MS: z.coerce.number().int().positive(),
VITE_ENABLE_ANALYTICS: z.enum(['true', 'false']),
})
Standard Schema is a shared interface supported by
Zod, Valibot, ArkType, and other validation libraries. Match your schema keys to
the prefix your bundler entry checks. Use VITE_ for Vite, PUBLIC_ for
Rsbuild, NEXT_PUBLIC_ for Next.js, or your chosen envPrefix for webpack and
Rspack.
Every variable arrives as a string, so parse numbers and booleans from strings as shown above. Validation only checks values and does not change what your application reads at runtime.
Schemas can validate synchronously or asynchronously. If a schema throws or
rejects, the validator logs the error message and throws Invalid environment variables with the original error as cause. Issues with no path print under
root.
Configure your bundler
Each bundler has its own subpath export. Choose the one your project uses.
Vite
// vite.config.ts
import { defineConfig } from 'vite'
import * as z from 'zod'
import { validateEnv } from '@pixelmatters/validate-env/vite'
const envSchema = z.object({
VITE_API_URL: z.url(),
})
export default defineConfig({
plugins: [validateEnv(envSchema)],
})
The plugin runs in Vite's configResolved hook and validates what Vite's
loadEnv returns for the current mode. It reads .env* files from envDir and
the process environment, filtered by envPrefix (VITE_ by default). Changes
other plugins make to root, envDir, or envPrefix are already applied.
Moving from @pixelmatters/vite-plugin-validate-env only requires changing the
dependency and import path to @pixelmatters/validate-env/vite. The plugin, its
name, and its output stay the same.
webpack and Rspack
// webpack.config.mjs (use '@pixelmatters/validate-env/rspack' in rspack.config.mjs)
import * as z from 'zod'
import { validateEnv } from '@pixelmatters/validate-env/webpack'
const envSchema = z.object({
PUBLIC_API_URL: z.url(),
})
export default {
plugins: [validateEnv(envSchema, { envPrefix: 'PUBLIC_' })],
}
validateEnv(schema, options) returns a ValidateEnvPlugin, which you can also
create with new ValidateEnvPlugin(schema, options). It validates process.env
once per compiler before the first run or watchRun hook. That covers builds,
--watch, and dev servers.
Neither bundler reads .env files on its own. Load them first with node --env-file=.env or dotenv. Without envPrefix, the plugin validates all of
process.env.
Rsbuild
// rsbuild.config.ts
import { defineConfig } from '@rsbuild/core'
import * as z from 'zod'
import { validateEnv } from '@pixelmatters/validate-env/rsbuild'
const envSchema = z.object({
PUBLIC_API_URL: z.url(),
})
export default defineConfig({
plugins: [validateEnv(envSchema)],
})
The plugin runs in modifyRsbuildConfig after other plugins and validates every
import.meta.env.* entry in source.define. That includes public variables
Rsbuild loaded from .env* files and process.env for your --env-mode and
--env-dir. It also covers values added by other plugins or source.define.
This validates the exact values your bundle receives. A build that disables env
loading, such as --no-env or createRsbuild() without loadEnv, injects no
variables and fails any required key. Pass envPrefix to narrow validation to
matching names.
Next.js
// next.config.ts
import type { NextConfig } from 'next'
import * as z from 'zod'
import { withValidateEnv } from '@pixelmatters/validate-env/next'
const envSchema = z.object({
NEXT_PUBLIC_API_URL: z.url(),
})
const nextConfig: NextConfig = {}…
Description from the npm listing.
- environment
- nextjs
- pixelmatters
- rsbuild
- rsbuild-plugin
- rspack
- rspack-plugin
- schema
- standard
- tanstack-intent
- validate
- variables
- vite
- vite-plugin
- webpack
- webpack-plugin
README badge
Show your rank in a README or on your website. The badge updates automatically.
Charts
Images: 30d · 1y · all time · 1600×900 dark
Adoption over time
7/30/90-day growth
Ranking history
Listing placement
Listing placement
Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.
Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.
Recent observations
Full history (128)Similar npm Webpack plugins plugins
All 20 @pixelmatters/validate-env alternativesData source
Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.
Listing: https://www.npmjs.com/package/@pixelmatters/validate-env. First seen Nov 24, 2026; last successful collection Dec 6, 2026. See the methodology.