Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

报错 #50

Closed
lijunnba2009 opened this issue Jul 18, 2018 · 7 comments
Closed

报错 #50

lijunnba2009 opened this issue Jul 18, 2018 · 7 comments
Labels
bug:core Issues about layout, styles, scripts, etc.

Comments

@lijunnba2009
Copy link

ReferenceError: hexo is not defined
at Object. (C:\Users\63479\leeblog\themes\minos\scripts\10_i18n.js:103:1)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (C:\Users\63479\leeblog\node_modules\hexo\lib\hexo\index.js:219:21)
at C:\Users\63479\leeblog\themes\minos\scripts\99_content.js:4:92
at fs.readFile.then.script (C:\Users\63479\leeblog\node_modules\hexo\lib\hexo\index.js:232:12)
at tryCatcher (C:\Users\63479\leeblog\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (C:\Users\63479\leeblog\node_modules\bluebird\js\release\promise.js:512:31)
at Promise._settlePromise (C:\Users\63479\leeblog\node_modules\bluebird\js\release\promise.js:569:18)
at Promise._settlePromise0 (C:\Users\63479\leeblog\node_modules\bluebird\js\release\promise.js:614:10)
at Promise._settlePromises (C:\Users\63479\leeblog\node_modules\bluebird\js\release\promise.js:693:18)
at Promise._fulfill (C:\Users\63479\leeblog\node_modules\bluebird\js\release\promise.js:638:18)
at Promise._resolveCallback (C:\Users\63479\leeblog\node_modules\bluebird\js\release\promise.js:432:57)
at Promise._settlePromiseFromHandler (C:\Users\63479\leeblog\node_modules\bluebird\js\release\promise.js:524:17)
at Promise._settlePromise (C:\Users\63479\leeblog\node_modules\bluebird\js\release\promise.js:569:18)
at Promise._settlePromise0 (C:\Users\63479\leeblog\node_modules\bluebird\js\release\promise.js:614:10)
at Promise._settlePromises (C:\Users\63479\leeblog\node_modules\bluebird\js\release\promise.js:693:18)
at Promise._fulfill (C:\Users\63479\leeblog\node_modules\bluebird\js\release\promise.js:638:18)
ERROR Script load failed: themes\minos\scripts\01_check.js

@lijunnba2009
Copy link
Author

环境:
hexo: 3.7.1
hexo-cli: 1.1.0
os: Windows_NT 10.0.17134 win32 x64
http_parser: 2.7.0
node: 6.5.0
v8: 5.1.281.81
uv: 1.9.1
zlib: 1.2.8
ares: 1.10.1-DEV
icu: 57.1
modules: 48
openssl: 1.0.2h

@ppoffice
Copy link
Owner

@lijunnba2009 请尝试升级下node的版本。如果问题仍然存在,请帖一下博客的源代码地址,这样我可以调试一下。

@lijunnba2009
Copy link
Author

@ppoffice 尝试把node切到 8.11.3和6.9.5,仍报原先的错误,我的博客源码地址 https://github.com/lijunnba2009/leeblog

@ppoffice
Copy link
Owner

@lijunnba2009 我clone了你的博客并进行了测试,并没有发现你所说的问题。请首先确保安装了hexo-renderer-sass,并且使用hexo clean清除缓存,然后使用hexo g或者hexo s是否能正常生成博客文件。

$ hexo -v
hexo: 3.7.1
hexo-cli: 1.1.0
os: Windows_NT 10.0.17134 win32 x64
http_parser: 2.8.0
node: 8.11.2
v8: 6.2.414.54
uv: 1.19.1
zlib: 1.2.11
ares: 1.10.1-DEV
modules: 57
nghttp2: 1.29.0
napi: 3
openssl: 1.0.2o
icu: 60.1
unicode: 10.0
cldr: 32.0
tz: 2017c

@ppoffice ppoffice added discussion Any questions about this theme. invalid Issues that are not following the issue templates. labels Aug 2, 2018
@ppoffice ppoffice closed this as completed Aug 5, 2018
@poying
Copy link
Contributor

poying commented Mar 18, 2019

@ppoffice 遇到同樣的問題

問題在於 10_i18n.js,他總共被執行三次,其中兩次分別由 01_check.js99_content.js 執行,在這種情況下 10_i18n.js 得不到 global 的 hexo 變數。不確定問題發生在哪,但可以簡單粗暴地解決。

解法:在 01_check.js99_content.js 兩個檔案第一行加上 global.hexo = hexo

@poying
Copy link
Contributor

poying commented Mar 18, 2019

@ppoffice 補充

https://github.com/hexojs/hexo/blob/1b418b192d99202cbcda4e507c44af1a32dbc643/lib/hexo/index.js#L228

script = `(function(exports, require, module, __filename, __dirname, hexo){${script}});`;

hexo 變數在 Hexo 主程式定義的方式本就是 local 變數,並非 global,所已會遇到這個問題還滿合理的。不清楚為什麼其他人沒遇到這個問題。

poying added a commit to poying/hexo-theme-minos that referenced this issue Mar 18, 2019
poying added a commit to poying/hexo-theme-minos that referenced this issue Mar 18, 2019
@ppoffice
Copy link
Owner

ppoffice commented Mar 18, 2019

@poying 非常感谢您的提醒。经过排查,我发现这个问题与hexo-renderer-sass和hexo的scripts引用过程中的参数传递有关。

首先,导致你和上面题主报错的原因在于被require10_i18n.js中hexo变量确实不存在,而由于这个文件是由其他scripts引用的,引用者的本地hexo变量并没有借着require('./10_i18n')传入被引用的文件中,导致出错。

另外,其他人没有出错的原因在于他们安装的hexo-renderer-sass的版本较低。在其v0.3.1v0.3.2版本中,hexo变量被直接暴露给global,所以会使require('./10_i18n')中存在hexo,掩盖了这个bug
https://github.com/knksmith57/hexo-renderer-sass/blob/0.3.1/index.js#L6

ppoffice added a commit that referenced this issue Mar 18, 2019
@ppoffice ppoffice added bug:general Issues with this theme in general. and removed discussion Any questions about this theme. invalid Issues that are not following the issue templates. labels Mar 18, 2019
ChieloNewctle pushed a commit to ChieloNewctle/hexo-theme-minos that referenced this issue Mar 25, 2020
ChieloNewctle pushed a commit to ChieloNewctle/hexo-theme-minos that referenced this issue Mar 25, 2020
@ppoffice ppoffice added bug:core Issues about layout, styles, scripts, etc. and removed bug:general Issues with this theme in general. labels Jun 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug:core Issues about layout, styles, scripts, etc.
Projects
None yet
Development

No branches or pull requests

3 participants