Uninitialized constant Haml::Options

My previously-working middleman installs seem to have succumbed to the usual bitrot, and have abruptly started throwing the error:

bundler: failed to load command: middleman (/Users/angus/.rvm/gems/ruby-2.6.5/bin/middleman)
NameError: uninitialized constant Haml::Options
  /Users/angus/.rvm/gems/ruby-2.6.5/gems/middleman-core-5.0.0.rc.1/lib/middleman-core/renderers/haml.rb:49:in `initialize'
  /Users/angus/.rvm/gems/ruby-2.6.5/gems/middleman-core-5.0.0.rc.1/lib/middleman-core/extension_manager.rb:70:in `new' 
(rest of stack trace snipped)

I’m seeing this running locally on MacOS with middleman-5.0.0rc1 and haml-6.0, and remotely on Ubuntu with the same combination (it also occurred with a much older version of middleman, 2.3.3).

Has anyone else run across this issue, or can suggest a fix? Thank you.

I’m having the same issue on a brand new project.

ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]

All middleman commands result in:

/Users/levinotik/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/middleman-core-4.4.2/lib/middleman-core/renderers/haml.rb:49:in `initialize': uninitialized constant Haml::Options (NameError)

        ::Haml::Options.defaults[:context] = nil
              ^^^^^^^^^
	from /Users/levinotik/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/middleman-core-4.4.2/lib/middleman-core/extension_manager.rb:66:in `new'
	from /Users/levinotik/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/middleman-core-4.4.2/lib/middleman-core/extension_manager.rb:66:in `activate'
	from /Users/levinotik/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/middleman-core-4.4.2/lib/middleman-core/extensions.rb:120:in `block in auto_activate'
	from /Users/levinotik/.rbenv/versions/3.1.2/lib/ruby/3.1.0/set.rb:511:in `each_key'
	from /Users/levinotik/.rbenv/versions/3.1.2/lib/ruby/3.1.0/set.rb:511:in `each'
	from /Users/levinotik/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/middleman-core-4.4.2/lib/middleman-core/extensions.rb:117:in `auto_activate'
	from /Users/levinotik/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/middleman-core-4.4.2/lib/middleman-core/extension_manager.rb:28:in `auto_activate'
	from /Users/levinotik/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/middleman-core-4.4.2/lib/middleman-core/extension_manager.rb:20:in `block (2 levels) in initialize'
	from /Users/levinotik/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/middleman-core-4.4.2/lib/middleman-core/callback_manager.rb:57:in `instance_exec'
	from /Users/levinotik/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/middleman-core-4.4.2/lib/middleman-core/callback_manager.rb:57:in `block in execute'
	from /Users/levinotik/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/hamster-3.0.0/lib/hamster/vector.rb:1316:in `each'
	from /Users/levinotik/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/hamster-3.0.0/lib/hamster/vector.rb:1316:in `traverse_depth_first'
	from /Users/levinotik/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/hamster-3.0.0/lib/hamster/vector.rb:431:in `each'
	from /Users/levinotik/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/middleman-core-4.4.2/lib/middleman-core/callback_manager.rb:57:in `execute'
	from /Users/levinotik/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/contracts-0.13.0/lib/contracts/method_reference.rb:43:in `send_to'
	from /Users/levinotik/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/contracts-0.13.0/lib/contracts/call_with.rb:76:in `call_with'
	from /Users/levinotik/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/contracts-0.13.0/lib/contracts/method_handler.rb:138:in `block in redefine_method'
	from /Users/levinotik/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/middleman-core-4.4.2/lib/middleman-core/callback_manager.rb:28:in `block in install_methods!'
	from /Users/levinotik/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/middleman-core-4.4.2/lib/middleman-core/application.rb:280:in `initialize'
	from /Users/levinotik/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/middleman-cli-4.4.2/bin/middleman:49:in `new'
	from /Users/levinotik/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/middleman-cli-4.4.2/bin/middleman:49:in `<top (required)>'
	from /Users/levinotik/.rbenv/versions/3.1.2/bin/middleman:25:in `load'
	from /Users/levinotik/.rbenv/versions/3.1.2/bin/middleman:25:in `<main>'

Hello,

this issue is treated on middleman git

There is a workaround.

1 Like

You should use haml version below 6.0 on your local system.
You can check it using command haml -v.

Or

Force middleman to use haml below 6.0
by adding this to your gem.
gem 'haml', '>= 4.0.5', '< 6.0'