Best Practices warn by default
astro-doctor/no-process-env no-process-env
Disallow process.env in Astro files — use import.meta.env instead.
Why
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.
Examples
✗ 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> Configuration
Override the default severity in your ESLint config:
// eslint.config.js
import astroDoctorPlugin from '@santi020k/eslint-plugin-astro-doctor'
export default [
astroDoctorPlugin.configs.recommended,
{
rules: {
'astro-doctor/no-process-env': 'error', // or 'warn' or 'off'
},
},
]
Or in your doctor.config.ts:
export default {
rules: {
'astro-doctor/no-process-env': 'error',
},
}
All rules
-
astro-doctor/no-client-load-overuse -
astro-doctor/use-astro-image -
astro-doctor/require-image-dimensions -
astro-doctor/no-missing-alt -
astro-doctor/no-set-html -
astro-doctor/no-public-secret-env -
astro-doctor/prefer-class-list -
astro-doctor/no-blocking-script -
astro-doctor/no-unprocessed-script-surprises -
astro-doctor/no-missing-lang -
astro-doctor/require-island-fallback -
astro-doctor/no-process-env(this page) -
astro-doctor/prefer-content-collections