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 properties of undefined (reading 'length')

See original GitHub issue

environment:

vue3, vue-cli ^4.5 “codemirror”: “^5.63.3” chrome browser 93.0.4577.82(x86_64)

problem:

switch cm from small window to fullscreen, then click any where of the fullscreen invoke exception message in the browser console tab: codemirror.js?56b3:2354 Uncaught TypeError: Cannot read properties of undefined (reading ‘length’) at mapFromLineView (codemirror.js?56b3:2354) at prepareMeasureForLine (codemirror.js?56b3:2407) at cursorCoords (codemirror.js?56b3:2658) at scrollPosIntoView (codemirror.js?56b3:3460) at endOperation_finish (codemirror.js?56b3:3917) at endOperations (codemirror.js?56b3:3836) at eval (codemirror.js?56b3:3819) at finishOperation (codemirror.js?56b3:2058) at endOperation (codemirror.js?56b3:3816) at HTMLDivElement.eval (codemirror.js?56b3:3953)

the vue function to switch cm view mode is: fullScreen(type){ cm.setOption(“fullScreen”, !cm.getOption(“fullScreen”)); }

i have debug the code where exception throws, function mapFromLineView(lineView, line, lineN) { if (lineView.line == line) { return {map: lineView.measure.map, cache: lineView.measure.cache} } for (var i = 0; i < lineView.rest.length; i++) { if (lineView.rest[i] == line) { return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i]} } } for (var i$1 = 0; i$1 < lineView.rest.length; i$1++) { if (lineNo(lineView.rest[i$1]) > lineN) { return {map: lineView.measure.maps[i$1], cache: lineView.measure.caches[i$1], before: true} } } } when click on the fullscreen cm the method mapFromLineView will execute second for loop(first if not return true),the lineView.rest is undefine, so invoke “Uncaught TypeError: Cannot read properties of undefined (reading ‘length’)” exception

every click anywhere will throw the same exception

Xnip2021-10-22_01-00-36

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
losetimecommented, Oct 30, 2021

define variables directly, do not use responsive, such as: let instances = null const initEditor = () => { instances = CodeMirror.fromTextArea(textarea, options}) } This is currently feasible

1reaction
whereyougocommented, Oct 30, 2021

Thank you.It works. I have add this demo to the codemirror_demo project

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read properties of undefined (reading 'length') - TrackJS
This message indicates that our code expects to have an object with a length property, but that object was not present. length is...
Read more >
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, make...
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 >
Typeerror: Cannot Read Property 'length' of Undefined
Why the Typeerror: Cannot Read Property 'length' of Undefined Gets Triggered ... A typeerror length of undefined can indicate that the actual type ......
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