Middleman error – `block in replace_gem’: middleman-cli is not part of the bundle. Add it to Gemfile.

I ran into an error while setting up a Middleman site on my PC. I already had Ruby and RubyGems installed, so I followed the instructions to install Middleman and start a new Middleman site:

gem install middleman
middleman init project
cd project

The next step was to start the preview web server, which produced an error:

$ bundle exec middleman server
DL is deprecated, please use Fiddle
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/bundler-1.7.7/lib/bundler/r
ubygems_integration.rb:256:in `block in replace_gem': middleman-cli is not part
of the bundle. Add it to Gemfile. (Gem::LoadError)
from c:/RailsInstaller/Ruby2.1.0/bin/middleman:22:in `<main>'

I took a look at the Gemfile:

$ cat Gemfile
# If you do not have OpenSSL installed, change
# the following line to use 'http://'
source 'https://rubygems.org'

# For faster file watcher updates on Windows:
gem 'wdm', '~> 0.1.0', platforms: [:mswin, :mingw]

# Windows does not come with time zone data
gem 'tzinfo-data', platforms: [:mswin, :mingw, :jruby]

# Middleman Gems

That’s it–there’s nothing listed under the Middleman Gems. I appended a line to add the missing middleman-cli gem:

$ echo 'gem "middleman-cli"' >> Gemfile

I attempted to start the preview web server again:

$ bundle exec middleman server
DL is deprecated, please use Fiddle
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/middleman-cli-4.1.9/bin/middleman:3:in `require': cannot load such file -- middleman-core/profiling (LoadError)
from c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/middleman-cli-4.1.9/bin/middleman:3:in `<top (required)>'
from c:/RailsInstaller/Ruby2.1.0/bin/middleman:23:in `load'
from c:/RailsInstaller/Ruby2.1.0/bin/middleman:23:in `<main>'

Now it’s missing another item, middleman-core. I decided to take a look at which Middleman gems were installed on my system:

$ gem list --local | grep middleman
middleman (4.1.9)
middleman-cli (4.1.9)
middleman-core (4.1.9)

I appended another line to the Gemfile to add the missing middleman-core gem:

$ echo 'gem "middleman-core"' >> Gemfile

The preview web server then started successfully:

$ bundle exec middleman server
DL is deprecated, please use Fiddle
DL is deprecated, please use Fiddle
== The Middleman is loading
== View your site at "http://localhost:4567", "http://192.168.200.196:4567"
== Inspect your site configuration at "http://localhost:4567/__middleman", "http://192.168.200.196:4567/__middleman"

Visiting http://localhost:4567 displayed the following:

Screen capture of default Middleman page on preview web server.
Screen capture of default Middleman page on preview web server.

Presumably the missing gems are supposed to be included by default when setting up a new Middleman project. I’m not sure why they weren’t included in my project, but in case you are running into the same problem I hope you find this post helpful.

Leave a Reply

Your email address will not be published. Required fields are marked *