bubkoo / hexo-toc

📖 Insert a markdown TOC before posts be rendered.
MIT License
126 stars 17 forks source link

Cannot read property 'toc' of undefined #4

Closed xingxiudong closed 8 years ago

xingxiudong commented 9 years ago

run cmd "hexo g" error

D:\www\website>hexo g [error] HexoError: Process failed: _posts/2012-06-14-javascript-the-good-parts-r eading-notes-ch3.md TypeError: Cannot read property 'toc' of undefined at module.exports (D:\www\website\node_modules\hexo-toc\lib\filter.js:5:41) at C:\Users\xingx_000\AppData\Roaming\npm\node_modules\hexo\lib\post\render. js:77:9 at iterate (C:\Users\xingx_000\AppData\Roaming\npm\node_modules\hexo\node_mo dules\async\lib\async.js:149:13) at C:\Users\xingx_000\AppData\Roaming\npm\node_modules\hexo\node_modules\asy nc\lib\async.js:160:25 at C:\Users\xingx_000\AppData\Roaming\npm\node_modules\hexo\lib\post\render. js:87:11 at module.exports (C:\Users\xingx_000\AppData\Roaming\npm\node_modules\hexo\ lib\plugins\filter\titlecase.js:5:53) at C:\Users\xingx_000\AppData\Roaming\npm\node_modules\hexo\lib\post\render. js:77:9 at iterate (C:\Users\xingx_000\AppData\Roaming\npm\node_modules\hexo\node_mo dules\async\lib\async.js:149:13) at C:\Users\xingx_000\AppData\Roaming\npm\node_modules\hexo\node_modules\asy nc\lib\async.js:160:25 at C:\Users\xingx_000\AppData\Roaming\npm\node_modules\hexo\lib\post\render. js:87:11

D:\www\website\node_modules\hexo-toc\lib\filter.js as below:

var toc = require('markdown-toc'); var assign = require('object-assign');

module.exports = function (data) { var options = assign({}, this.config.toc); data.content = toc.insert(data.content, options); return data; };

Dir tree:

D:. ├─lib └─node_modules ├─.bin ├─markdown-toc │ ├─lib │ └─node_modules │ ├─concat-stream │ │ ├─node_modules │ │ │ ├─inherits │ │ │ ├─readable-stream │ │ │ │ ├─lib │ │ │ │ └─node_modules │ │ │ │ ├─core-util-is │ │ │ │ │ └─lib │ │ │ │ ├─isarray │ │ │ │ │ └─build │ │ │ │ └─string_decoder │ │ │ └─typedarray │ │ │ ├─example │ │ │ └─test │ │ │ └─server │ │ └─test │ │ └─server │ ├─extend-shallow │ │ └─node_modules │ │ └─kind-of │ ├─gray-matter │ │ ├─lib │ │ └─node_modules │ │ └─chalk │ │ └─node_modules │ │ ├─.bin │ │ ├─ansi-styles │ │ ├─escape-string-regexp │ │ ├─has-ansi │ │ │ └─node_modules │ │ │ ├─ansi-regex │ │ │ └─get-stdin │ │ ├─strip-ansi │ │ │ └─node_modules │ │ │ └─ansi-regex │ │ └─supports-color │ ├─markdown-link │ ├─minimist │ │ ├─example │ │ └─test │ ├─object.pick │ ├─remarkable │ │ ├─bin │ │ ├─dist │ │ ├─lib │ │ │ ├─common │ │ │ ├─configs │ │ │ ├─helpers │ │ │ ├─rules_block │ │ │ ├─rules_core │ │ │ └─rules_inline │ │ └─node_modules │ │ ├─argparse │ │ │ ├─examples │ │ │ ├─lib │ │ │ │ ├─action │ │ │ │ │ ├─append │ │ │ │ │ └─store │ │ │ │ ├─argument │ │ │ │ └─help │ │ │ └─node_modules │ │ │ ├─underscore │ │ │ └─underscore.string │ │ │ └─lib │ │ └─autolinker │ │ ├─dist │ │ ├─src │ │ │ ├─htmlParser │ │ │ ├─match │ │ │ └─matchParser │ │ └─tests │ │ └─htmlParser │ └─repeat-string └─object-assign

Please help me, thanks.

bubkoo commented 9 years ago

npm uninstall hexo-toc --save remove it, then reinstall with npm install hexo-toc --save.

xingxiudong commented 9 years ago

The problem is going on with your commented.....

After run "hexo clean", run "hexo g":

D:\www\website>hexo g [error] HexoError: Process failed: _posts/2012-06-14-javascript-the-good-parts-r eading-notes-ch2.md TypeError: Cannot read property 'toc' of undefined at module.exports (D:\www\website\node_modules\hexo-toc\lib\filter.js:5:41) at C:\Users\xingx_000\AppData\Roaming\npm\node_modules\hexo\lib\post\render. js:77:9 at iterate (C:\Users\xingx_000\AppData\Roaming\npm\node_modules\hexo\node_mo dules\async\lib\async.js:149:13) at C:\Users\xingx_000\AppData\Roaming\npm\node_modules\hexo\node_modules\asy nc\lib\async.js:160:25 at C:\Users\xingx_000\AppData\Roaming\npm\node_modules\hexo\lib\post\render. js:87:11 at module.exports (C:\Users\xingx_000\AppData\Roaming\npm\node_modules\hexo\ lib\plugins\filter\titlecase.js:5:53) at C:\Users\xingx_000\AppData\Roaming\npm\node_modules\hexo\lib\post\render. js:77:9 at iterate (C:\Users\xingx_000\AppData\Roaming\npm\node_modules\hexo\node_mo dules\async\lib\async.js:149:13) at C:\Users\xingx_000\AppData\Roaming\npm\node_modules\hexo\node_modules\asy nc\lib\async.js:160:25 at C:\Users\xingx_000\AppData\Roaming\npm\node_modules\hexo\lib\post\render. js:87:11

But no "Cannot find module 'markdown-toc'" error found when run “require('markdown-toc');” after running "node" command: D:\www\website>node

require('markdown-toc'); { [Function: toc] insert: [Function: insert], bullets: [Function: bullets], linkify: [Function: linkify], slugify: [Function: slugify], titleize: [Function: titleize], strip: [Function: strip] }

bubkoo commented 9 years ago

The latest version of hexo-toc is v0.0.3, and make sure the markdown-toc module was installed:

.
├── node_modules
    ├── hexo-toc
        ├── lib
        └── node_modules
            ├── markdown-toc
            └── object-assign