3 min read

hexo missing the generate and server commands

Today I thought I’d try hexo on a new project. A few minutes in and I’d stumbled across a strange problem that took me 20 minutes too long to figure out.

If I ran hexo init my-project I could run hexo generate and get a compiled version of a new site just fine. The issue was I wanted to use hexo in an existing git project and so copied across the files I thought I needed manually.

Having moved and merged all the files I ran hexo generate but rather than getting a shiny compiled set of .html files, I got this:

$ hexo generate

Usage: hexo <command>

Commands:
  help     Get help on a command.
  init     Create a new Hexo folder.
  version  Display version information.

Global Options:
  --config  Specify config file instead of using _config.yml
  --cwd     Specify the CWD
  ...

Ah, no generate command!! I Googled for the answer but came up short. I resorted to doing a diff on a clean hexo project v.s. my repository. The difference was that my package.json file had no “hexo” property.

Hexo package.json diff

A quick copy/paste of the hexo property and I was in business:

$ hexo generate

Usage: hexo <command>

Commands:
  clean     Remove generated files and cache.
  config    Get or set configurations.
  deploy    Deploy your website.
  generate  Generate static files.
  help      Get help on a command.
  init      Create a new Hexo folder.
  list      List the information of the site
  migrate   Migrate your site from other system to Hexo.
  new       Create a new post.
  publish   Moves a draft post from _drafts to _posts folder.
  render    Render files with renderer plugins.
  server    Start the server.
  version   Display version information.

Global Options:
  --config  Specify config file instead of using _config.yml
  --cwd     Specify the CWD
  ...

TLDR: If your hexo generate/server command is missing, make sure package.json contains:

{ "hexo": { "version": "x.x.x" } }