Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

147
Vistas
AWS Lambda object initialized outside try catch scope throws ReferenceError: Cannot access 'user' before initialization

I'm running into some strange behavior on Lambda running Node 14.x. I have a helper function which the main handler function calls, and it contains an user object defined outside of a try catch block. When I log it, it gives me back an object, but then immediately inside the try catch block, user is undefined. Namely I get this error:

ReferenceError: Cannot access 'user' before initialization

This is not the case for strings and numbers, as demonstrated by id. However, client is also an object, but it's accessible inside the try catch, so I'm confused by this behavior. Would appreciate if someone could provide some insight.

const helperFunction = async (payload, context, pool) => { 
    let { user } = payload; 
    let { id } = payload.user;

    console.log(user); // <-- this is is defined

    let client = await pool.connect();
    try {
        console.log(client); // <-- this is defined
        console.log(id); // <-- this is defined

        console.log(user); // <-- this is throws reference error, cannot access before initialization
        
        ...
    } catch (e) {
        console.log(e);
    }

My user object looks like this:

{
  id: '16',
  email: 'example@gmail.com',
  subscriptions: [ '', 'a', 'b' ],
  iat: 1633376553
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda