www/apps/resources/app/lint/rules/admin-env-vars-import-meta/page.mdx
export const metadata = {
title: admin-env-vars-import-meta - ESLint plugin rules,
}
This rule requires admin code to use import.meta.env instead of process.env for environment variables, since admin code is bundled for the browser by Vite.
warn. This rule is enabled in the recommended preset.
This rule targets files in your project's src/admin directory. It reports access to process.env.
The following code is reported by the rule:
const url = process.env.VITE_BACKEND_URL
Instead, use import.meta.env:
const url = import.meta.env.VITE_BACKEND_URL
Admin code runs in the browser via Vite, where process.env is undefined. Using import.meta.env ensures your environment variables resolve correctly at runtime.
Learn more in the Environment Variables in Admin Development documentation.
This rule is auto-fixable. Run the linter with the --fix option to apply the fix automatically.
To turn off this rule, set it to off in your ESLint configuration:
import { defineConfig } from "eslint/config"
import medusa from "@medusajs/eslint-plugin"
export default defineConfig([
...medusa.configs.recommended,
{
rules: {
"@medusajs/admin-env-vars-import-meta": "off",
},
},
])
Or disable it for a single line using an inline comment:
// eslint-disable-next-line @medusajs/admin-env-vars-import-meta
console.log(process.env.MEDUSA_BACKEND_URL)