Hexo: TypeError: Cannot set property 'lastIndex' of undefined

Created on 30 Jan 2017  ·  6Comments  ·  Source: hexojs/hexo

Environment Info

Node version(node -v)

v7.4.0

Plugin version(npm ls --depth 0)

rapiz@sig ~/Blog $ npm ls --depth 0
[email protected] /home/rapiz/Blog
├── [email protected]
├── [email protected] -> /home/rapiz/Blog/node_modules/.0.2.0@hexo-deployer-git
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] -> /home/rapiz/Blog/node_modules/.3.0.2@hexo-math
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] -> /home/rapiz/Blog/node_modules/.0.6.0@katex extraneous
└── [email protected] -> /home/rapiz/Blog/node_modules/.0.1.0@match-at extraneous

npm ERR! extraneous: [email protected] /home/rapiz/Blog/node_modules/katex
npm ERR! extraneous: [email protected] /home/rapiz/Blog/node_modules/match-at

For BUG

rapiz@sig ~/Blog $ hexo g
INFO  [hexo-inject] installing hotfix for hexojs/hexo#1791
INFO  [hexo-math] Using engine 'mathjax'
INFO  Start processing
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
TypeError: Cannot set property 'lastIndex' of undefined
    at highlight (/home/rapiz/Blog/node_modules/highlight.js/lib/highlight.js:514:35)            
    at /home/rapiz/Blog/node_modules/highlight.js/lib/highlight.js:564:21                        
    at Array.forEach (native)                                                                    
    at Object.highlightAuto (/home/rapiz/Blog/node_modules/highlight.js/lib/highlight.js:563:40) 
    at highlight (/home/rapiz/Blog/node_modules/hexo-util/lib/highlight.js:100:19)               
    at highlightUtil (/home/rapiz/Blog/node_modules/hexo-util/lib/highlight.js:22:14)            
    at /home/rapiz/Blog/node_modules/hexo/lib/plugins/filter/before_post_render/backtick_code_block.js:49:15                                                                                      
    at RegExp.[Symbol.replace] (native)                                                          
    at String.replace (native)                                                                   
    at Hexo.backtickCodeBlock (/home/rapiz/Blog/node_modules/hexo/lib/plugins/filter/before_post_render/backtick_code_block.js:15:31)                                                             
    at Hexo.tryCatcher (/home/rapiz/Blog/node_modules/bluebird/js/release/util.js:16:23)         
    at Hexo.<anonymous> (/home/rapiz/Blog/node_modules/bluebird/js/release/method.js:15:34)      
    at /home/rapiz/Blog/node_modules/hexo/lib/extend/filter.js:68:35                             
    at tryCatcher (/home/rapiz/Blog/node_modules/bluebird/js/release/util.js:16:23)              
    at Object.gotValue (/home/rapiz/Blog/node_modules/bluebird/js/release/reduce.js:155:18)      
    at Object.gotAccum (/home/rapiz/Blog/node_modules/bluebird/js/release/reduce.js:144:25)      
    at Object.tryCatcher (/home/rapiz/Blog/node_modules/bluebird/js/release/util.js:16:23)       
    at Promise._settlePromiseFromHandler (/home/rapiz/Blog/node_modules/bluebird/js/release/promise.js:510:31)                                                                                    
    at Promise._settlePromise (/home/rapiz/Blog/node_modules/bluebird/js/release/promise.js:567:18)                                                                                               
    at Promise._settlePromiseCtx (/home/rapiz/Blog/node_modules/bluebird/js/release/promise.js:604:10)                                                                                            
    at Async._drainQueue (/home/rapiz/Blog/node_modules/bluebird/js/release/async.js:138:12)     
    at Async._drainQueues (/home/rapiz/Blog/node_modules/bluebird/js/release/async.js:143:10)    
    at Immediate.Async.drainQueues (/home/rapiz/Blog/node_modules/bluebird/js/release/async.js:17:14)                                                                                             
    at runCallback (timers.js:651:20)                                                            
    at tryOnImmediate (timers.js:624:5)                                                          
    at processImmediate [as _immediateCallback] (timers.js:596:5)                                
FATAL Cannot set property 'lastIndex' of undefined
TypeError: Cannot set property 'lastIndex' of undefined
    at highlight (/home/rapiz/Blog/node_modules/highlight.js/lib/highlight.js:514:35)            
    at /home/rapiz/Blog/node_modules/highlight.js/lib/highlight.js:564:21                        
    at Array.forEach (native)                                                                    
    at Object.highlightAuto (/home/rapiz/Blog/node_modules/highlight.js/lib/highlight.js:563:40) 
    at highlight (/home/rapiz/Blog/node_modules/hexo-util/lib/highlight.js:100:19)               
    at highlightUtil (/home/rapiz/Blog/node_modules/hexo-util/lib/highlight.js:22:14)            
    at /home/rapiz/Blog/node_modules/hexo/lib/plugins/filter/before_post_render/backtick_code_block.js:49:15                                                                                      
    at RegExp.[Symbol.replace] (native)                                                          
    at String.replace (native)                                                                   
    at Hexo.backtickCodeBlock (/home/rapiz/Blog/node_modules/hexo/lib/plugins/filter/before_post_render/backtick_code_block.js:15:31)                                                             
    at Hexo.tryCatcher (/home/rapiz/Blog/node_modules/bluebird/js/release/util.js:16:23)         
    at Hexo.<anonymous> (/home/rapiz/Blog/node_modules/bluebird/js/release/method.js:15:34)      
    at /home/rapiz/Blog/node_modules/hexo/lib/extend/filter.js:68:35                             
    at tryCatcher (/home/rapiz/Blog/node_modules/bluebird/js/release/util.js:16:23)
    at Object.gotValue (/home/rapiz/Blog/node_modules/bluebird/js/release/reduce.js:155:18)
    at Object.gotAccum (/home/rapiz/Blog/node_modules/bluebird/js/release/reduce.js:144:25)
    at Object.tryCatcher (/home/rapiz/Blog/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/rapiz/Blog/node_modules/bluebird/js/release/promise.js:510:31)
    at Promise._settlePromise (/home/rapiz/Blog/node_modules/bluebird/js/release/promise.js:567:18)
    at Promise._settlePromiseCtx (/home/rapiz/Blog/node_modules/bluebird/js/release/promise.js:604:10)
    at Async._drainQueue (/home/rapiz/Blog/node_modules/bluebird/js/release/async.js:138:12)
    at Async._drainQueues (/home/rapiz/Blog/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (/home/rapiz/Blog/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:651:20)
    at tryOnImmediate (timers.js:624:5)
    at processImmediate [as _immediateCallback] (timers.js:596:5)

Most helpful comment

Setting auto_detect: false in _config.yml resolved this for me:

_config.yml

highlight: 
  enable: true
  line_number: false
  auto_detect: false
  tab_replace:

All 6 comments

Found the same issue here: https://github.com/hexojs/hexo/issues/1913
Why should I set auto_detect to false?

The auto_detect is set for detecting language automatically, https://github.com/hexojs/hexo-util#highlightstr-options

I assume the issue is caused by when the highlight.js tries to detect the code language.

got the same issue, after change the
```scala xx ```
to
```js xxx ```
hexo is back

Setting auto_detect: false in _config.yml resolved this for me:

_config.yml

highlight: 
  enable: true
  line_number: false
  auto_detect: false
  tab_replace:

The solution provided here just gives me another error. See my ticket #3486 with some more details and ideas to finally find a real solution to this issue.

这是因为在你的博客中,在用代码段`````时没有指明语言,这时候如果你的auto_detect: true,就会产生这个错误。
解决的话:

  1. 找到那篇文章没有指明语言,随便加上一个就行。
  2. 如果找不到哪篇博客,
    2.1 可以在\myBlognode_modules\hexo\lib\hexorender.js中的第51、52行加上
    console.log(data.path);
    console.log(data.text);
    查看在哪篇博客之后出现的问题。
    2.2 然后,设置auto_detect: false,运行hexo g,查看生成文章的顺序,在2.1找到的文章之后的那篇文章,基本就是你没有指明语言的文章了。
    2.3 此时给他随便指明一个语言,然后可以吧render.js中加的两行删掉,设置auto_detect: true,运行hexo cleanhexo g即可解决
Was this page helpful?
0 / 5 - 0 ratings

Related issues

LouisBarranqueiro picture LouisBarranqueiro  ·  28Comments

pod4g picture pod4g  ·  24Comments

fishercoder1534 picture fishercoder1534  ·  26Comments

scaljeri picture scaljeri  ·  44Comments

curbengh picture curbengh  ·  21Comments