Cannot find name `process`
Started a new nuxt 4 project, but unable to use
process.env.NUXT_ENV_NAME_HERE
error message:
8 Replies
Hi @LeFtHitD. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
In Nuxt 3/4, you generally shouldn’t read envs via process.env in app code. Use runtimeConfig instead, and override it with NUXT… variables.
- Define keys in nuxt.config:
- Set environment variables (dev/build use .env; production set real envs):
- Read in code:
Only NUXT_-prefixed vars can override runtimeConfig at runtime, and .env is not read in production; set platform envs instead. Avoid mapping to differently named process.env vars in nuxt.config—works only at build time. [Runtime config; Env file; Nuxt configuration]
If you still need process.env types (e.g., inside build-time code or nuxt.config), install Node types and let Nuxt generate TS configs:
- Install: npm i -D typescript vue-tsc (Nuxt handles TS configs). [TypeScript]
- Run nuxt dev/build to generate .nuxt/tsconfig.*.json, which include Node typings for the appropriate contexts. [Auto-generated types]
But for runtime app code, prefer useRuntimeConfig over process.env. [Runtime config]
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@189715647293423616> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@kapa.ai I am using
process.env only in nuxt.config.ts, however it gives type errorLet me check the knowledge base for you again. One moment! :books:
----------------------
Short answer: it’s safe to use process.env in nuxt.config.ts (build-time context), but your TypeScript types aren’t picking up Node globals. Enable Node typings for the “node/build-time” context.
Options:
- Rely on Nuxt’s generated tsconfigs
- Run nuxt dev or nuxt build so Nuxt generates .nuxt/tsconfig.node.json with proper Node types for nuxt.config and modules. [Auto-generated types; TS config splitting]
- If needed, customize via typescript.nodeTsConfig or typescript.tsConfig in nuxt.config. [TS config splitting; nuxt.config typescript]
- Add Node types yourself
- Install types: npm i -D typescript vue-tsc (and optionally @types/node if your editor still needs it). [TypeScript]
- Ensure your root tsconfig extends or references .nuxt/tsconfig.node.json (generated after nuxt dev/build), or include "types": ["node"] in compilerOptions of a node-specific config.
Reminder: For app/runtime code, prefer runtimeConfig over process.env, and only NUXT_-prefixed envs can override at runtime; .env is not read in production. [Runtime config; .env]
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@189715647293423616> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@kapa.ai i saw
tsconfig.node.json types is empty, is this expected?Let me check the knowledge base for you again. One moment! :books:
----------------------
Yes—seeing an (effectively) empty types list in .nuxt/tsconfig.node.json can be expected. Nuxt splits TypeScript configs by context (app, server, shared, node/build-time). The node context is for nuxt.config and modules, and you can customize it via typescript.nodeTsConfig if you need additional typings (e.g., Node types) for your setup. [TS config splitting; nuxt.config typescript]
If your editor reports process/env types missing in nuxt.config.ts, run nuxt dev/build to regenerate the context tsconfigs, or add the necessary types via typescript.nodeTsConfig. [Auto-generated types; TS config splitting]
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@189715647293423616> Kapa.ai is still learning and improving, please let me know how I did by reacting below.