今天新装Hexo时遇到了个很费解的问题,也谷歌不出答案。
所以来这里求助:
问题是这样的,使用
npm install hexo-generator-sitemap --save
安装hexo-generator-sitemap插件
lurrpis:lurrpis lurrpis$ npm install hexo-generator-sitemap --save
[email protected] node_modules/hexo-generator-sitemap
├── [email protected]
└── [email protected]
没有报错,
但是hexo generate时,报错:
ERROR Plugin load failed: hexo-generator-sitemap
ReferenceError: hexo is not defined
at Object.<anonymous> (/Users/lurrpis/webroot/hexo/lurrpis/node_modules/hexo-generator-sitemap/sitemap.js:4:10)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (/Users/lurrpis/webroot/hexo/lurrpis/node_modules/hexo/lib/hexo/index.js:213:21)
at /Users/lurrpis/webroot/hexo/lurrpis/node_modules/hexo-generator-sitemap/index.js:6:33
at /Users/lurrpis/webroot/hexo/lurrpis/node_modules/hexo/lib/hexo/index.js:229:12
at tryCatcher (/Users/lurrpis/webroot/hexo/lurrpis/node_modules/hexo/node_modules/bluebird/js/main/util.js:24:31)
at Promise._settlePromiseFromHandler (/Users/lurrpis/webroot/hexo/lurrpis/node_modules/hexo/node_modules/bluebird/js/main/promise.js:454:31)
at Promise._settlePromiseAt (/Users/lurrpis/webroot/hexo/lurrpis/node_modules/hexo/node_modules/bluebird/js/main/promise.js:530:18)
at Promise._settlePromises (/Users/lurrpis/webroot/hexo/lurrpis/node_modules/hexo/node_modules/bluebird/js/main/promise.js:646:14)
at Async._drainQueue (/Users/lurrpis/webroot/hexo/lurrpis/node_modules/hexo/node_modules/bluebird/js/main/async.js:79:16)
at Async._drainQueues (/Users/lurrpis/webroot/hexo/lurrpis/node_modules/hexo/node_modules/bluebird/js/main/async.js:89:10)
at Immediate.Async.drainQueues [as _onImmediate] (/Users/lurrpis/webroot/hexo/lurrpis/node_modules/hexo/node_modules/bluebird/js/main/async.js:14:14)
at processImmediate [as _immediateCallback] (timers.js:358:17)
我在我的WEB服务器上也做了同样地测试,报错也同上
测试安装hexo-migrator-wordpress和hexo-generator-feed插件也报如上错误。
请问如何解决这个问题,谢谢!
我本地使用的是Mac,使用pkg安装的nodejs v0.12.0,
使用npm install hexo-cli -g 安装的Hexo.
再次感谢
我也遇到這個問題,只好退回 hexo 2.8.3 使用。
nodejs使用0.11试试看
Try hexo-generator-sitemap@1 instead.
I have similar issue on the following plugins:
ERROR Plugin load failed: hexo-generator-baidu-sitemap
ReferenceError: hexo is not defined
ERROR Plugin load failed: hexo-yuidoc
ReferenceError: hexo is not defined
btw are you still using YUIDoc to generate api documentation? I see there's a brand new design of hexo website but I can't find api docs anymore. @tommy351
我使用
npm install hexo-generator-sitemap@1 --save
npm install hexo-generator-feed@1 --save
解决了问题
十分感谢 @tommy351
@nantas I don't use YUIDoc to generate API doc now. I'm writing the new API doc currently.
I encountered the same situation.
ERROR Plugin load failed: hexo-generator-baidu-sitemap
ReferenceError: hexo is not defined
at Object.<anonymous> (/Users/rxread/Code/Personal/GithubBlog/node_modules/hexo-generator-baidu-sitemap/baidusitemap.js:4:10)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:1
And then I tried
npm install hexo-generator-baidu-sitemap@1 --save
But it didn't work as expected.

npm-debug.log file
0 info it worked if it ends with ok
1 verbose cli [ 'node',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli 'install',
1 verbose cli 'hexo-generator-baidu-sitemap@1',
1 verbose cli '--save' ]
2 info using [email protected]
3 info using [email protected]
4 verbose install initial load of /Users/rxread/Code/Personal/GithubBlog/package.json
5 verbose installManyTop reading scoped package data from /Users/rxread/Code/Personal/GithubBlog/node_modules/hexo/package.json
6 verbose installManyTop reading scoped package data from /Users/rxread/Code/Personal/GithubBlog/node_modules/hexo-generator-alias/package.json
7 verbose installManyTop reading scoped package data from /Users/rxread/Code/Personal/GithubBlog/node_modules/hexo-generator-archive/package.json
8 verbose installManyTop reading scoped package data from /Users/rxread/Code/Personal/GithubBlog/node_modules/hexo-generator-baidu-sitemap/package.json
9 verbose installManyTop reading scoped package data from /Users/rxread/Code/Personal/GithubBlog/node_modules/hexo-generator-category/package.json
10 verbose installManyTop reading scoped package data from /Users/rxread/Code/Personal/GithubBlog/node_modules/hexo-generator-feed/package.json
11 verbose installManyTop reading scoped package data from /Users/rxread/Code/Personal/GithubBlog/node_modules/hexo-generator-index/package.json
12 verbose installManyTop reading scoped package data from /Users/rxread/Code/Personal/GithubBlog/node_modules/hexo-generator-sitemap/package.json
13 verbose installManyTop reading scoped package data from /Users/rxread/Code/Personal/GithubBlog/node_modules/hexo-generator-tag/package.json
14 verbose installManyTop reading scoped package data from /Users/rxread/Code/Personal/GithubBlog/node_modules/hexo-migrator-rss/package.json
15 verbose installManyTop reading scoped package data from /Users/rxread/Code/Personal/GithubBlog/node_modules/hexo-renderer-ejs/package.json
16 verbose installManyTop reading scoped package data from /Users/rxread/Code/Personal/GithubBlog/node_modules/hexo-renderer-marked/package.json
17 verbose installManyTop reading scoped package data from /Users/rxread/Code/Personal/GithubBlog/node_modules/hexo-renderer-stylus/package.json
18 verbose installManyTop reading scoped package data from /Users/rxread/Code/Personal/GithubBlog/node_modules/hexo-server/package.json
19 info package.json [email protected] license should be a valid SPDX license expression
20 info package.json [email protected] license should be a valid SPDX license expression
21 info package.json [email protected] license should be a valid SPDX license expression
22 info package.json [email protected] license should be a valid SPDX license expression
23 verbose readDependencies loading dependencies from /Users/rxread/Code/Personal/GithubBlog/package.json
24 silly cache add args [ 'hexo-generator-baidu-sitemap@1', null ]
25 verbose cache add spec hexo-generator-baidu-sitemap@1
26 silly cache add parsed spec { raw: 'hexo-generator-baidu-sitemap@1',
26 silly cache add scope: null,
26 silly cache add name: 'hexo-generator-baidu-sitemap',
26 silly cache add rawSpec: '1',
26 silly cache add spec: '>=1.0.0 <2.0.0',
26 silly cache add type: 'range' }
27 silly addNamed hexo-generator-baidu-sitemap@>=1.0.0 <2.0.0
28 verbose addNamed ">=1.0.0 <2.0.0" is a valid semver range for hexo-generator-baidu-sitemap
29 silly addNameRange { name: 'hexo-generator-baidu-sitemap',
29 silly addNameRange range: '>=1.0.0 <2.0.0',
29 silly addNameRange hasData: false }
30 silly mapToRegistry name hexo-generator-baidu-sitemap
31 silly mapToRegistry using default registry
32 silly mapToRegistry registry https://registry.npmjs.org/
33 silly mapToRegistry uri https://registry.npmjs.org/hexo-generator-baidu-sitemap
34 verbose addNameRange registry:https://registry.npmjs.org/hexo-generator-baidu-sitemap not in flight; fetching
35 verbose request uri https://registry.npmjs.org/hexo-generator-baidu-sitemap
36 verbose request no auth needed
37 info attempt registry request try #1 at 02:17:49
38 verbose request id b8568423b2f09a2e
39 verbose etag "5BRNKZD5GZXCNMQKOCHETXBKV"
40 http request GET https://registry.npmjs.org/hexo-generator-baidu-sitemap
41 http 304 https://registry.npmjs.org/hexo-generator-baidu-sitemap
42 silly get cb [ 304,
42 silly get { date: 'Thu, 03 Sep 2015 18:17:49 GMT',
42 silly get via: '1.1 varnish',
42 silly get 'cache-control': 'max-age=60',
42 silly get etag: '"5BRNKZD5GZXCNMQKOCHETXBKV"',
42 silly get age: '0',
42 silly get connection: 'keep-alive',
42 silly get 'x-served-by': 'cache-sjc3133-SJC',
42 silly get 'x-cache': 'MISS',
42 silly get 'x-cache-hits': '0',
42 silly get 'x-timer': 'S1441304269.743303,VS0,VE37',
42 silly get vary: 'Accept' } ]
43 verbose etag https://registry.npmjs.org/hexo-generator-baidu-sitemap from cache
44 verbose get saving hexo-generator-baidu-sitemap to /Users/rxread/.npm/registry.npmjs.org/hexo-generator-baidu-sitemap/.cache.json
45 silly addNameRange number 2 { name: 'hexo-generator-baidu-sitemap',
45 silly addNameRange range: '>=1.0.0 <2.0.0',
45 silly addNameRange hasData: true }
46 silly addNameRange versions [ 'hexo-generator-baidu-sitemap',
46 silly addNameRange [ '0.0.1',
46 silly addNameRange '0.0.2',
46 silly addNameRange '0.0.3',
46 silly addNameRange '0.0.4',
46 silly addNameRange '0.0.5',
46 silly addNameRange '0.0.6',
46 silly addNameRange '0.0.7',
46 silly addNameRange '0.0.8',
46 silly addNameRange '0.1.0',
46 silly addNameRange '0.1.1' ] ]
47 verbose stack Error: No compatible version found: hexo-generator-baidu-sitemap@'>=1.0.0 <2.0.0'
47 verbose stack Valid install targets:
47 verbose stack ["0.0.1","0.0.2","0.0.3","0.0.4","0.0.5","0.0.6","0.0.7","0.0.8","0.1.0","0.1.1"]
47 verbose stack
47 verbose stack at installTargetsError (/usr/local/lib/node_modules/npm/lib/cache/add-named.js:278:12)
47 verbose stack at next (/usr/local/lib/node_modules/npm/lib/cache/add-named.js:256:19)
47 verbose stack at setData (/usr/local/lib/node_modules/npm/lib/cache/add-named.js:230:5)
47 verbose stack at RES (/usr/local/lib/node_modules/npm/node_modules/inflight/inflight.js:23:14)
47 verbose stack at f (/usr/local/lib/node_modules/npm/node_modules/once/once.js:17:25)
47 verbose stack at fixName (/usr/local/lib/node_modules/npm/lib/cache/add-named.js:29:5)
47 verbose stack at saved (/usr/local/lib/node_modules/npm/lib/cache/caching-client.js:173:7)
47 verbose stack at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/polyfills.js:210:7
47 verbose stack at Object.oncomplete (fs.js:107:15)
48 verbose cwd /Users/rxread/Code/Personal/GithubBlog
49 error Darwin 14.5.0
50 error argv "node" "/usr/local/bin/npm" "install" "hexo-generator-baidu-sitemap@1" "--save"
51 error node v0.10.32
52 error npm v2.14.1
53 error code ETARGET
54 error notarget No compatible version found: hexo-generator-baidu-sitemap@'>=1.0.0 <2.0.0'
54 error notarget Valid install targets:
54 error notarget ["0.0.1","0.0.2","0.0.3","0.0.4","0.0.5","0.0.6","0.0.7","0.0.8","0.1.0","0.1.1"]
54 error notarget
54 error notarget This is most likely not a problem with npm itself.
54 error notarget In most cases you or one of your dependencies are requesting
54 error notarget a package version that doesn't exist.
54 error notarget
54 error notarget It was specified as a dependency of 'hexo-site'
55 verbose exit [ 1, true ]
npm i -S hexo-generator-json-content@1
解决了问题
非常感谢 @tommy351
npm i -S hexo-generator-json-content@1
解决了问题
非常感谢 @tommy351
你们的办法试了都没用,我因为有多个hexo项目,所以我把另外的项目的package-lock.json和package.json还有整个node_modules目录都删除然后把正常的hexo中对应文件拷贝过来再执行hexo s 和hexo g 都正常了
你们的办法试了都没用,我因为有多个hexo项目,所以我把另外的项目的package-lock.json和package.json还有整个node_modules目录都删除然后把正常的hexo中对应文件拷贝过来再执行hexo s 和hexo g 都正常了
Most helpful comment
Try
hexo-generator-sitemap@1instead.