Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda