Samisdat / hexo-staging

Simple staging to https://hexo.io/
MIT License
0 stars 0 forks source link

Cannot read property 'options' of undefined while running `hexo generate --staging development` #1

Open tijme opened 7 years ago

tijme commented 7 years ago

Hi,

First of all thanks for making this plugin, it works like a charm (well, almost) 😄!

I ran npm install hexo-staging --save to install the plugin and added the following variables to my config.

stagings:
  production:
    url: https://example.ltd
    root: /
  development:
    url: http://localhost/blog/public
    root: /blog/public/

When trying to generate my blog on my development environment (using hexo generate --staging development) I get the following error.

device:blog user$ hexo generate --staging development
ERROR Plugin load failed: hexo-staging
TypeError: Cannot read property 'options' of undefined
    at module.exports (/Users/user/Sites/blog/node_modules/hexo-staging/lib/cli.js:33:15)
    at /Users/user/Sites/blog/node_modules/hexo-staging/index.js:61:28
    at /Users/user/Sites/blog/node_modules/hexo/lib/hexo/index.js:232:12
    at tryCatcher (/Users/user/Sites/blog/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/user/Sites/blog/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/Users/user/Sites/blog/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/Users/user/Sites/blog/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/Users/user/Sites/blog/node_modules/bluebird/js/release/promise.js:693:18)
    at Promise._fulfill (/Users/user/Sites/blog/node_modules/bluebird/js/release/promise.js:638:18)
    at Promise._resolveCallback (/Users/user/Sites/blog/node_modules/bluebird/js/release/promise.js:432:57)
    at Promise._settlePromiseFromHandler (/Users/user/Sites/blog/node_modules/bluebird/js/release/promise.js:524:17)
    at Promise._settlePromise (/Users/user/Sites/blog/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/Users/user/Sites/blog/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/Users/user/Sites/blog/node_modules/bluebird/js/release/promise.js:693:18)
    at Promise._fulfill (/Users/user/Sites/blog/node_modules/bluebird/js/release/promise.js:638:18)
    at /Users/user/Sites/blog/node_modules/bluebird/js/release/nodeback.js:42:21
    at /Users/user/Sites/blog/node_modules/graceful-fs/graceful-fs.js:78:16
    at tryToString (fs.js:513:3)
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:501:12)

This prevents the site from building correctly. I had to update cli.js to prevent it from setting server options if cli.server is undefined. See the code below.

    if (cli.server) {
        cli.server.options.arguments = [
            { name: '--staging', desc: 'Define staging [' + stagings.join('|') + ']' }
        ];
    }

I am using Hexo version 3.3.9.

ilokhov commented 7 years ago

I can confirm that I get the same error using Hexo version 3.3.9. and that the code alteration suggested by @tijme solved the problem for me.