Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!