Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

258
Vistas
Why are destructured environment variables undefined in Next.js?

In my Next.js app I've created a .env file with a variable named API_KEY.

Destructuring the value results in undefined, as shown here:

const { API_KEY } = process.env; // = undefined
const key = process.env.API_KEY; // = 'value'

Can someone please explain why process.env isn't populated with the correct value here?

9 months ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

From the docs:

Note: In order to keep server-only secrets safe, Next.js replaces process.env.* with the correct values at build time. This means that process.env is not a standard JavaScript object, so you’re not able to use object destructuring.

and for client-side React components

The value will be inlined into JavaScript sent to the browser because of the NEXT_PUBLIC_ prefix. This inlining occurs at build time, so your various NEXT_PUBLIC_ envs need to be set when the project is built.

9 months ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos