question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property "length" of undefined

See original GitHub issue

If you pass a regExp as second argument in function reactStringReplace you can get error like: Cannot read property "length" of undefined. I think thiss is caused by the work of vanilla replace method.

For example, this code give us an error (it’s cyrillic): const str = ‘Справка Форма Ф9’; const re = /(справка[а-я].?(по)? форм[а-я] [ф|Ф]\d)/gi console.log(str.split(re)); // [“”, “Справка Форма Ф9”, undefined, “”]

So you cannot get length proprty of undefined. And this error will crush you page. Example_of_undefined

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
iansinnottcommented, May 2, 2022

Agreed, I pushed a change that should fix this. Thanks for raising the issue. Will publish in next version.

0reactions
alex-clearcommented, May 2, 2022

@iansinnott Thanks for remark. You are right, there was an issue with our regex however, IMO, in order to prevent error throws, better to add the solution above(or in existed PR), or to add try catch to the code(maybe return error with ‘wrong regex provided’ or something similar)

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read property 'length' of Undefined in JS
The "Cannot read property 'length' of undefined" error occurs when accessing the length property on an undefined value. To solve the error, ...
Read more >
Typeerror: Cannot Read Property 'length' of Undefined
A typeerror length of undefined can indicate that the actual type of an operand is different from the expected type. This error can...
Read more >
[SOLVED] Cannot Read Property 'length' of Undefined in JS
4 Quick Fixes for the “Cannot Read Property 'length' of Undefined” Error in JavaScript · 1. Use an if Statement · 2. Use...
Read more >
Cannot read property length of undefined - Stack Overflow
The error means that what ever element is returned by getElementById('WallSearch') , it does not have a value property. Every form field has...
Read more >
Cannot read property 'length' of undefined - Treehouse
Cannot read property 'length' of undefined. Hi, i doing "Using Logic in Pug". I followed along with the video and checked another studens ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found