Skip to content

添加hexo-plugin-gitalk依赖后,hexo server, hexo generate无法运行 #7

@lulu010722

Description

@lulu010722

报错信息:

C:\Users\38466\Desktop\blog>hexo server
INFO  Validating config
Inferno is in development mode.
INFO  Start processing
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
TypeError: Cannot read properties of undefined (reading 'gitalk')
    at Hexo.<anonymous> (C:\Users\38466\Desktop\blog\node_modules\hexo-plugin-gitalk\index.js:2:41)
    at Hexo.tryCatcher (C:\Users\38466\Desktop\blog\node_modules\bluebird\js\release\util.js:16:23)
    at Hexo.<anonymous> (C:\Users\38466\Desktop\blog\node_modules\bluebird\js\release\method.js:15:34)
    at C:\Users\38466\Desktop\blog\node_modules\hexo\lib\extend\filter.js:67:52
    at tryCatcher (C:\Users\38466\Desktop\blog\node_modules\bluebird\js\release\util.js:16:23)
    at Object.gotValue (C:\Users\38466\Desktop\blog\node_modules\bluebird\js\release\reduce.js:166:18)
    at Object.gotAccum (C:\Users\38466\Desktop\blog\node_modules\bluebird\js\release\reduce.js:155:25)
    at Object.tryCatcher (C:\Users\38466\Desktop\blog\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\Users\38466\Desktop\blog\node_modules\bluebird\js\release\promise.js:547:31)
    at Promise._settlePromise (C:\Users\38466\Desktop\blog\node_modules\bluebird\js\release\promise.js:604:18)
    at Promise._settlePromise0 (C:\Users\38466\Desktop\blog\node_modules\bluebird\js\release\promise.js:649:10)
    at Promise._settlePromises (C:\Users\38466\Desktop\blog\node_modules\bluebird\js\release\promise.js:729:18)
    at _drainQueueStep (C:\Users\38466\Desktop\blog\node_modules\bluebird\js\release\async.js:93:12)
    at _drainQueue (C:\Users\38466\Desktop\blog\node_modules\bluebird\js\release\async.js:86:9)
    at Async._drainQueues (C:\Users\38466\Desktop\blog\node_modules\bluebird\js\release\async.js:102:5)
    at Async.drainQueues [as _onImmediate] (C:\Users\38466\Desktop\blog\node_modules\bluebird\js\release\async.js:15:14)
    at process.processImmediate (node:internal/timers:485:21)

推测原因:node_modules\hexo-plugin-gitalk\index.js

hexo.extend.filter.register('after_post_render', function(data) {
	var gitalkConfig = hexo.config.plugins.gitalk; // <------------这里可能因为hexo的配置接口已经改了,导致hexo.config下没有plugins这个字段
	if (gitalkConfig) {
		data.content = data.content + '\n<div id="gitalk-container"></div>\n<script src="https://cdn.bootcss.com/blueimp-md5/2.12.0/js/md5.min.js"></script><link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css"><script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>';
		var str = `
		<script>
		var gitalkConfig = ${JSON.stringify(gitalkConfig)};
	    gitalkConfig.id = md5(location.pathname);
		var gitalk = new Gitalk(gitalkConfig);
	    gitalk.render("gitalk-container");
	    </script>`;
		
		data.content = data.content + '\n' + str;
	}

	return data;
});

如果想复现,就在上面console.log一下hexo.config就行

(当然这种年久失修的老仓库应该没人维护了吧。。)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions