Nuxt

nuxt/runtime-config-not-process-env

App code reads configuration with useRuntimeConfig() and tests the side with import.meta.client, not process.env or process.client.

umiarkowanastatycznefe-nuxt

Dlaczego

process.env does not exist in the browser bundle and, on the server, .env is read only in development: process.env.API_URL in a component is undefined in the browser and in production unless the platform sets it, so the bug appears only after deploy. Runtime config is set once, overridable with NUXT_ variables, and typed.

Poprawka

Declare the value in nuxt.config under runtimeConfig (public only when the browser needs it) and read it with useRuntimeConfig(): useRuntimeConfig().public.apiBase. Set it in production with NUXT_PUBLIC_API_BASE. Test the side with import.meta.client, import.meta.server and import.meta.dev.

Przykłady

// bad
const api = process.env.API_URL
if (process.client) track()
// good
const api = useRuntimeConfig().public.apiBase
if (import.meta.client) track()

Źródła

Fakty

Identyfikator
nuxt/runtime-config-not-process-env
Waga
umiarkowana
Sprawdzanie
statyczne sprawdzane w kodzie źródłowym przez audit
Dotyczy plików
vue jsx
Tylko w projektach z
nuxt
Uczy jej skill
fe-nuxt Nuxt apps
Od wersji
0.1.0

Plik reguły na GitHubie

Przeczytaj w terminalu

npx github:dawidolko/frontend-skills explain nuxt/runtime-config-not-process-env