Back to Medusa

{metadata.title}

www/apps/resources/app/lint/rules/admin-env-vars-import-meta/page.mdx

2.17.01.7 KB
Original Source

export const metadata = { title: admin-env-vars-import-meta - ESLint plugin rules, }

{metadata.title}

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.

Severity

warn. This rule is enabled in the recommended preset.

What it Targets

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:

tsx
const url = process.env.VITE_BACKEND_URL

Instead, use import.meta.env:

tsx
const url = import.meta.env.VITE_BACKEND_URL

Why it's Important

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.

Fixable

This rule is auto-fixable. Run the linter with the --fix option to apply the fix automatically.

Turn it Off

To turn off this rule, set it to off in your ESLint configuration:

ts
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:

ts
// eslint-disable-next-line @medusajs/admin-env-vars-import-meta
console.log(process.env.MEDUSA_BACKEND_URL)