no-process-env
Disallow process.env in Astro files — use import.meta.env instead.
astro-doctor/no-process-env
Why it matters
process.env is a Node.js-specific API that does not work in client-side contexts. import.meta.env is Astro's standard for environment variables: it works in both server and client code, respects the PUBLIC_ prefix for client-safe exposure, and is type-safe with the Astro env schema.
See the difference
Incorrect
Using process.env
---
const apiKey = process.env.API_KEY
const publicUrl = process.env.PUBLIC_SITE_URL
---
<p>{publicUrl}</p>Correct
Using import.meta.env
---
const apiKey = import.meta.env.API_KEY
const publicUrl = import.meta.env.PUBLIC_SITE_URL
---
<p>{publicUrl}</p>Configure this check
Override the default severity in your ESLint config:
import astroDoctorPlugin from '@santi020k/eslint-plugin-astro-doctor'
export default [
astroDoctorPlugin.configs.recommended,
{
rules: {
'astro-doctor/no-process-env': 'error',
},
},
]Or set the severity for CLI scans in doctor.config.ts:
export default {
rules: {
'astro-doctor/no-process-env': 'error',
},
}Use 'error', 'warn', or 'off'. The configuration guide covers presets and per-file overrides.
Keep exploring best practices
- prefer-class-listUse class:list directive for conditional or dynamic class names.
- prefer-content-collectionsPrefer Content Collections over Astro.glob() or import.meta.glob() for Markdown and MDX files.
- no-legacy-astro-7-experimental-flagsMigrate experimental configuration fields removed or stabilized in Astro 7.
- prefer-env-schemaDefine an Astro env schema for variables documented in .env.example.
- prefer-pnpmUse pnpm consistently and remove competing package-manager lockfiles.
- require-client-router-script-lifecycleInitialize scripts on astro:page-load when using ClientRouter.
- require-content-configAdd a content config when src/content contains entries.
- require-fetch-default-exportRequire a default export from Astro 7 advanced-routing entrypoints.