Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Function yaml.safeLoad is removed in js-yaml 4. Use yaml.load instead, which is now safe by default. #222

Open
miozus opened this issue Jul 5, 2021 · 2 comments

Comments

@miozus
Copy link

miozus commented Jul 5, 2021

hexo server --debug

Error: Function yaml.safeLoad is removed in js-yaml 4. Use yaml.load instead, which is now safe by default.
    at Object.safeLoad (/Users/username/hexo/blog/node_modules/[email protected]@js-yaml/index.js:10:11)
    **at getSettings (/Users/username/hexo/blog/node_modules/[email protected]@hexo-admin/api.js:44:26)**
    at /Users/username/hexo/blog/node_modules/[email protected]@hexo-admin/api.js:150:14
    at /Users/username/hexo/blog/node_modules/[email protected]@hexo-admin/api.js:141:7
    at call (/Users/username/hexo/blog/node_modules/[email protected]@connect/index.js:239:7)
    at next (/Users/username/hexo/blog/node_modules/[email protected]@connect/index.js:183:5)
    at next (/Users/username/hexo/blog/node_modules/[email protected]@connect/index.js:161:14)
    at jsonParser (/Users/username/hexo/blog/node_modules/[email protected]@body-parser/lib/types/json.js:110:7)
    at call (/Users/username/hexo/blog/node_modules/[email protected]@connect/index.js:239:7)
    at next (/Users/username/hexo/blog/node_modules/[email protected]@connect/index.js:183:5)
    at SendStream.error (/Users/username/hexo/blog/node_modules/[email protected]@serve-static/index.js:121:7)
    at SendStream.emit (events.js:376:20)
    at SendStream.error (/Users/username/hexo/blog/node_modules/[email protected]@send/index.js:270:17)
    at SendStream.onStatError (/Users/username/hexo/blog/node_modules/[email protected]@send/index.js:421:12)
    at next (/Users/username/hexo/blog/node_modules/[email protected]@send/index.js:735:16)
    at onstat (/Users/username/hexo/blog/node_modules/[email protected]@send/index.js:724:14)
    at FSReqCallback.oncomplete (fs.js:192:21)

package.json

 "dependencies": {
    "hexo": "^5.0.0",
    "hexo-admin": "^2.3.0",
...
@miozus
Copy link
Author

miozus commented Jul 5, 2021

		// reads admin panel settings from _admin-config.yml
    // or writes it if it does not exist
    function getSettings() {
        var path = hexo.base_dir + '_admin-config.yml'
        if (!fs.existsSync(path)) {
            hexo.log.d('admin config not found, creating one')
            fs.writeFile(hexo.base_dir + '_admin-config.yml', '')
            return {}
        } else {
            var settings = yml.load(fs.readFileSync(path))
//                              ⬆️  safeLoad -> load
														
            if (!settings) return {}
            return settings
        }

其实呢,hexo 版本升级后语法(js-yaml)要求更严格,直接定位,修改老版本的源码就能运行啦

考虑有的同学还在用老版本,我也不知怎么获取版本做兼容,所以没提PR

@jerryoung
Copy link

版本兼容,我已经实现会,谢谢楼主。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants