github-markdown-preview: unitialized constant GitHub (NameError)
Hiya,
I’m ruby 2.2.0 and I just installed github-markdown-preview using gem install. I got this stacktrace:
/home/wasd/.rubies/ruby-2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require': uninitialized constant GitHub (NameError)
from /home/wasd/.rubies/ruby-2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require'
from /home/wasd/.gem/ruby/2.2.0/gems/html-pipeline-1.11.0/lib/html/pipeline/markdown_filter.rb:2:in `<top (required)>'
from /home/wasd/.gem/ruby/2.2.0/gems/github-markdown-preview-3.1.3/lib/github-markdown-preview/html_preview.rb:68:in `pipeline_filters'
from /home/wasd/.gem/ruby/2.2.0/gems/github-markdown-preview-3.1.3/lib/github-markdown-preview/html_preview.rb:41:in `initialize'
from /home/wasd/.gem/ruby/2.2.0/gems/github-markdown-preview-3.1.3/bin/github-markdown-preview:31:in `new'
from /home/wasd/.gem/ruby/2.2.0/gems/github-markdown-preview-3.1.3/bin/github-markdown-preview:31:in `<top (required)>'
from /home/wasd/.gem/ruby/2.2.0/bin/github-markdown-preview:23:in `load'
from /home/wasd/.gem/ruby/2.2.0/bin/github-markdown-preview:23:in `<main>'
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 20 (11 by maintainers)
@dmarcotte I ran into this issue, and I believe that I have figured out the root cause.
If rubygems is in a state with zero unresolved dependencies, it just uses the built-in ruby require:
This is the normal state when you boot IRB:
However, after requiring this gem,
unresolved_depsis non-empty. This is because rubygems also considers development dependencies, and does not eager-load everything.This forces rubygems to use the
Gem::Specifications to find the file path:In general, this should be fine; the gemspecs should contain the correct path information.
However, in November 2014, as part of a performance optimization, rubygems changed the code to use the full file path, instead of the relative path.
Unfortunately, there was a bug in the method to compute the full path:
Namely, that it doesn’t properly handle cases with C extensions (because they have multiple valid paths).
The
github/markdowngem falls into this scenario:So rubygems chooses the first one, which is not actually requirable by itself:
And that is where our mysterious error comes from!
Fortunately, this bug was fixed at the end of May 2015:
So this explains the inconsistency: only certain versions of rubygems will experience the issue.
As for solutions, you could just force people to upgrade (or downgrade, I suppose) their rubygems. However, I believe that there is a simpler and more elegant way.
Namely, if you explicitly require
github/markdown.rb(as opposed togithub/markdown) it will not match on the extension’s .bundle file.It needs to happen before
HTML::Pipeline::MarkdownFiltergets loaded, so I would place the require at the top of lib/github-markdown-preview/html_preview.rb: