title: Javascript: TypeError: Cannot convert undefined or null to object
body: <p>I'm reading a text file and converting it to JSON format using regex in my react project.It is working fine but when including in my code it is giving 
      TypeError: Cannot convert undefined or null to object
  There is some problem while performing replace but I am unable to understand the problem. Please help me out in resolving this issue. </p>
  
  <p>I think the problem is <code>allText = allText.replace(/\s{2,}|\n+/g, " ");</code> is not getting completed.</p>