tufu9441 / maupassant-hexo

A simple Hexo theme forked from icylogic.
https://www.haomwei.com
MIT License
2.63k stars 669 forks source link

TypeError: Cannot read property 'length' of null #450

Closed rama291041610 closed 4 years ago

rama291041610 commented 5 years ago

For BUG

PS>hexo s
INFO  Start processing
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
TypeError: Cannot read property 'length' of null
    at subMode (E:\software\blog\hexo\node_modules\highlight.js\lib\highlight.js:388:42)
    at processLexeme (E:\software\blog\hexo\node_modules\highlight.js\lib\highlight.js:497:22)
    at highlight (E:\software\blog\hexo\node_modules\highlight.js\lib\highlight.js:581:17)
    at E:\software\blog\hexo\node_modules\highlight.js\lib\highlight.js:627:21
    at Array.forEach (<anonymous>)
    at Object.highlightAuto (E:\software\blog\hexo\node_modules\highlight.js\lib\highlight.js:626:62)
    at E:\software\blog\hexo\node_modules\hexo-util\lib\highlight.js:117:25
    at highlight (E:\software\blog\hexo\node_modules\hexo-util\lib\highlight.js:120:7)
    at highlightUtil (E:\software\blog\hexo\node_modules\hexo-util\lib\highlight.js:22:14)
    at data.content.data.content.replace (E:\software\blog\hexo\node_modules\hexo\lib\plugins\filter\before_post_render\backtick_code_block.js:59:15)
    at String.replace (<anonymous>)
    at Hexo.backtickCodeBlock (E:\software\blog\hexo\node_modules\hexo\lib\plugins\filter\before_post_render\backtick_code_block.js:14:31)
    at Hexo.tryCatcher (E:\software\blog\hexo\node_modules\bluebird\js\release\util.js:16:23)
    at Hexo.<anonymous> (E:\software\blog\hexo\node_modules\bluebird\js\release\method.js:15:34)
    at Promise.each.filter (E:\software\blog\hexo\node_modules\hexo\lib\extend\filter.js:63:65)
    at tryCatcher (E:\software\blog\hexo\node_modules\bluebird\js\release\util.js:16:23)
    at Object.gotValue (E:\software\blog\hexo\node_modules\bluebird\js\release\reduce.js:155:18)
    at Object.gotAccum (E:\software\blog\hexo\node_modules\bluebird\js\release\reduce.js:144:25)
    at Object.tryCatcher (E:\software\blog\hexo\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (E:\software\blog\hexo\node_modules\bluebird\js\release\promise.js:512:31)
    at Promise._settlePromise (E:\software\blog\hexo\node_modules\bluebird\js\release\promise.js:569:18)
    at Promise._settlePromiseCtx (E:\software\blog\hexo\node_modules\bluebird\js\release\promise.js:606:10)

For question

Sometimes when I execute “hexo s" or "hexo g", hexo will throw TypeError like above. Sometimes it can works without error. The same code but different results.

How can I solve the problem?

There is my code.

https://github.com/rama291041610/250.ac.cn

tufu9441 commented 5 years ago

我也不知道为何会出现不同的情况……

Jesse121 commented 5 years ago

我也碰到这个问题,解决方法如下 在highlight.js文件中的subMode函数中添加一个判断即可

function subMode(lexeme, mode) {
      var i, length;
      if(mode.contains){ //判断该属性是否存在
        for (i = 0, length = mode.contains.length; i < length; i++) {
          if (testRe(mode.contains[i].beginRe, lexeme)) {
            if (mode.contains[i].endSameAsBegin) {
              mode.contains[i].endRe = escapeRe( mode.contains[i].beginRe.exec(lexeme)[0] );
            }
            return mode.contains[i];
          }
        }
      } 
    }