N
Nuxt3mo ago
LeFt_HitD

Cannot find name `process`

Started a new nuxt 4 project, but unable to use process.env.NUXT_ENV_NAME_HERE error message:
Cannot find name process . Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add node to the types field in your tsconfig.
Cannot find name process . Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add node to the types field in your tsconfig.
8 Replies
kapa.ai
kapa.ai3mo ago
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:
export default defineNuxtConfig({
runtimeConfig: {
// server-only
apiSecret: '',
// exposed to client
public: {
envName: '' // will be overridden by NUXT_PUBLIC_ENV_NAME
}
}
})
export default defineNuxtConfig({
runtimeConfig: {
// server-only
apiSecret: '',
// exposed to client
public: {
envName: '' // will be overridden by NUXT_PUBLIC_ENV_NAME
}
}
})
- Set environment variables (dev/build use .env; production set real envs):
NUXT_PUBLIC_ENV_NAME="staging"
NUXT_PUBLIC_ENV_NAME="staging"
- Read in code:
const config = useRuntimeConfig()
console.log(config.public.envName)
const config = useRuntimeConfig()
console.log(config.public.envName)
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: ----------------------
kapa.ai
kapa.ai3mo ago
<@189715647293423616> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
LeFt_HitD
LeFt_HitDOP3mo ago
@kapa.ai I am using process.env only in nuxt.config.ts, however it gives type error
kapa.ai
kapa.ai3mo ago
Let 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: ----------------------
kapa.ai
kapa.ai3mo ago
<@189715647293423616> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
LeFt_HitD
LeFt_HitDOP3mo ago
@kapa.ai i saw tsconfig.node.json types is empty, is this expected?
kapa.ai
kapa.ai3mo ago
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: ----------------------
kapa.ai
kapa.ai3mo ago
<@189715647293423616> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?