Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8950933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:33:04+00:00 2026-06-15T13:33:04+00:00

I came across a really strange bug with Javascript on NodeJS. I have a

  • 0

I came across a really strange bug with Javascript on NodeJS.

I have a huge data.json file (24MB). I read it via

var data = JSON.parse(fs.readFileSync("./data.json", 'utf8'));

However, at some point during the script execution, I try to access, for example,

data['someProp']['prop1']

and it raises a type error:

TypeError: Cannot read property ‘prop1’ of undefined

It is really strange because data, data['someProp'], data['someProp']['prop1'] are all defined.

If I do

console.log(data['someProp']['prop1']);

it displays the value of data['someProp']['prop1'] on the screen correctly and raises a type error immediately.

What might cause this strange behaviour? Any guess or tip to fix such a problem?


Update:

Let me be a bit clearer. I find it strange because if I put

console.log(data['someProp']['prop1']);

in the line just above where it raised the error, it correctly prints out the value and immediately raises an error.

Let’s say data['someProp']['prop1'] = "someProp value".

Then this is the error log.

someProp value

console.log(data['someProp']['prop1']);
                        ^

TypeError: Cannot read property 'prop1' of undefined

So if I do

console.log(data['someProp'])

Then this is the log I get:

{
  ...
  "someProp": {
    "prop1": "someProp value"
  },
  ...
}
undefined

This is the part I’m confused. When I console.log it, it prints out the contents of data['someProp'] followed immediately by undefined. What can cause this?

Another strange thing is

console.log(typeof data['someProp']);

The result is:

object
undefined

How can data['someProp'] be object as well as undefined?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:33:05+00:00Added an answer on June 15, 2026 at 1:33 pm

    Okay, I’ll answer my own question and close this question.

    As user1689607 guessed, there was a bug with my async code. For example, my code looked like:

    function test(done) {
      ...
      if (err) {
        done();
      }
      ...
      if (data['someProp']['prop1']) {
        ...
        done();
      }
    }
    

    Since the first done() was called without return, I think it comes back at the end of the callback execution and goes through the rest of the code, which it shouldn’t. During that time, there has been some changes to data and that’s what caused the error.

    So return done(); fixed the problem.

    Thanks @user1689607.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I came across the SkipList data structure. It really helped me to solve
I recently came across a JavaScript file in our source tree with lots of
recently I came across this term,but really have no idea what it refers to.I've
I came across a carousel from Twitter bootstrap here. http://twitter.github.com/bootstrap/javascript.html#carousel It looks really good.
Came across a problem whereby I wanted the last time data was imported to
I came across this due to a bug in my code and I'm curious
Whilst reading through the book The well grounded Rubyist, I came across some strange
I was looking over some mock OCJP questions. I came across a really baffling
I just came across a C++ SDK that makes heavy use of this really
I just came across Google Native Client Now, it looks really interesting that they

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.