Monaco-editor: Cannot read property 'kind' of undefined error is shown when deselecting some text

Created on 1 Nov 2017  路  5Comments  路  Source: microsoft/monaco-editor

monaco-editor version: 0.10.1
Browser: Google Chrome
OS: Windows 10

  1. Open the Monaco Playground: https://microsoft.github.io/monaco-editor/playground.html
  2. Add some comment block to the default javascript code so that the final model looks like this:
function hello() {
  alert('Hello world!');
}
/*
NativeScript adheres to the CommonJS specification for dealing with
JavaScript modules. The CommonJS require() function is how you import
JavaScript modules defined in other files.
*/
  1. Select a portion of the text as shown in the attached video and click outside to deselect it

Actual result: The text is deselected but the following error is printed to the browser console:

Uncaught Error: Cannot read property 'kind' of undefined

TypeError: Cannot read property 'kind' of undefined
    at Object._t [as isJsxOpeningElement] (typescriptServices.js:33)
    at Object.r [as getDocumentHighlights] (typescriptServices.js:59)
    at C (typescriptServices.js:65)
    at D (typescriptServices.js:65)
    at Object.x [as getOccurrencesAtPosition] (typescriptServices.js:65)
    at e.getOccurrencesAtPosition (worker.js:9)
    at t.e.fmr (workerMain.js:7)
    at t._handleMessage (workerMain.js:7)
    at Object.handleMessage (workerMain.js:7)
    at e._handleMessage (workerMain.js:7)
    at Object._t [as isJsxOpeningElement] (typescriptServices.js:33)
    at Object.r [as getDocumentHighlights] (typescriptServices.js:59)
    at C (typescriptServices.js:65)
    at D (typescriptServices.js:65)
    at Object.x [as getOccurrencesAtPosition] (typescriptServices.js:65)
    at e.getOccurrencesAtPosition (worker.js:9)
    at t.e.fmr (workerMain.js:7)
    at t._handleMessage (workerMain.js:7)
    at Object.handleMessage (workerMain.js:7)
    at e._handleMessage (workerMain.js:7)
    at editor.main.js:31

Expected result: The text is deselected without errors

Repro demo:
error_repro

P.S. The same error also happens in TypeScript files.

bug monaco-typescript

Most helpful comment

I also encountered such a problem.

615

All 5 comments

I also encountered such a problem.

615

Error Stack

image

Workaround

So far I had to hack a temporal solution for these mouse event errors:

Problem:

The TypeScriptServices file has methods that do not check for e to be defined before evaluating e.kind, they are short event check functions like function bt(e){ return 123===e.kind}. There are more than 250 in the minified file (/monaco-editor/dev/vs/language/typescript/lib/typescriptServices.js, yep, minified in the dev path)

Fix:

Add the is-defined check to e so it looks like function bt(e){return e && 123===e.kind}.

Batch Fix

In the file /monaco-editor/min/vs/language/typescript/lib/typescriptServices.js (and /monaco-editor/dev/vs/language/typescript/lib/typescriptServices.js):
Replace occurrences of /return ([0-9][0-9]*)===e.kind/ with /return e&&$1===e.kind/ . /.../ are regexps.

getting still the error when pressing up till the first row:

Uncaught Error: Cannot read property 'kind' of undefined

@jagenjo What version of the editor are you using?

Was this page helpful?
0 / 5 - 0 ratings