weixin_39725118
weixin_39725118
2020-12-09 06:55

Error: Cannot read property 'getTokens' of null

Issue


Uncaught TypeError: Cannot read property 'getTokens' of null
    at EditSession.getTokens (scripts.js:10056)
    at Text.$renderLine (scripts.js:16782)
    at Text.$renderLinesFragment (scripts.js:16549)
    at Text.update (scripts.js:16575)
    at VirtualRenderer.$renderChanges (scripts.js:18572)
    at RenderLoop._flush (scripts.js:17270)

Refers to this line: https://github.com/ajaxorg/ace/blob/9b5b63d1dc7c1b81b58d30c87d14b5905d030ca5/lib/ace/edit_session.js#L338

Where bgTokenizer is not defined.

The issue occurs non-deterministic and could be timing related. It occurs with karma, when executing unit tests. It occurs 0-n times in a test run. The application works and looks like it doesn't have this problem. I'm not sure, if this issue is related to ng2-ace-editor, ace, angular, karma or how I use ng2-ace-editor or somewhere in between.

Environment

html
<div id="editor" ace-editor>
</div>
ts
import { Component, Input, Output, EventEmitter } from '/core';

({
  selector: 'app-ace-editor',
  templateUrl: './ace-editor.component.html',
  styleUrls: ['./ace-editor.component.css']
})
export class AceEditorComponent {
  ()
  text = '';

  ()
  textChange = new EventEmitter<string>();

  options = {
    fontSize: '16px',
    maxLines: 20
  };

  onChange(text = '') {
    this.textChange.emit(text);
  }
}
</string>
Relevant dependencies

"ng2-ace-editor": "0.3.8",
"ace-mode-solidity": "0.1.0",
"karma": "~1.7.1",
"/core": "^6.1.0",

angular.json contains:


"scripts": [
              "./node_modules/ace-builds/src-min/ace.js",
              "./node_modules/ace-builds/src-min/theme-dawn.js",
              "./node_modules/ace-mode-solidity/build/remix-ide/mode-solidity.js"
]

image

该提问来源于开源项目:fxmontigny/ng2-ace-editor

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

5条回答

  • qq_33297737 天涯生聚 1月前

    i solve the problem just by change my iterator key,the cause of this problem is the instance of editor has be destoryed and replace of a new Instance,thus the cursor position or other states stored by  the former instance could not be get now,lead the error.i've write the details in my blog.

    https://blog.csdn.net/qq_33297737/article/details/114361081?spm=1001.2014.3001.5501

    点赞 评论 复制链接分享
  • weixin_39737764 weixin_39737764 4月前

    I just ran into the same issue on 0.3.9

    点赞 评论 复制链接分享
  • weixin_39637571 weixin_39637571 4月前

    It still exists in 0.3.9

    点赞 评论 复制链接分享
  • weixin_39895283 weixin_39895283 4月前

    Bumped into the same issue but if I rolled back to 0.3.4, it seems to be fine.

    点赞 评论 复制链接分享
  • weixin_39725118 weixin_39725118 4月前

    I removed theme, mode and options to get a small example with the issue still occuring.

    html
    <div ace-editor></div>
    
    ts
    import { Component, Input, Output, EventEmitter } from '/core';
    
    ({
      selector: 'app-ace-editor',
      templateUrl: './ace-editor.component.html',
      styleUrls: ['./ace-editor.component.css']
    })
    export class AceEditorComponent {
      ()
      text = '';
    
      ()
      textChange = new EventEmitter<string>();
    }
    </string>
    
    "scripts": [
                  "./node_modules/ace-builds/src-min/ace.js"
    ]
    
    
    Uncaught TypeError: Cannot read property 'getTokens' of null
        at EditSession.getTokens (scripts.js:10056)
        at Text.$renderLine (scripts.js:16782)
        at Text.$renderLinesFragment (scripts.js:16549)
        at Text.update (scripts.js:16575)
        at VirtualRenderer.$renderChanges (scripts.js:18572)
        at RenderLoop._flush (scripts.js:17270)
    

    I also tried to use the component variant instead of the directive. There is no difference.

    Update

    My current "workaround" (not really) is to mock the component with ng2-mock-component.

    点赞 评论 复制链接分享

为你推荐