untra / polyglot

:abc: Multilingual and i18n support tool for Jekyll Blogs
https://polyglot.untra.io
MIT License
410 stars 59 forks source link

NoMethodError thrown when running jekyll serve --incremental #89

Closed kerner1000 closed 4 years ago

kerner1000 commented 6 years ago

I run bundle exec jekyll serve --incremental and get the following:

Remote Theme: Using theme mmistakes/jekyll-theme-basically-basic
/var/lib/gems/2.3.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/patches/jekyll/site.rb:154:in `relativize_urls': undefined method `gsub!' for nil:NilClass (NoMethodError)
    from /var/lib/gems/2.3.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/patches/jekyll/site.rb:115:in `block in process_documents'
    from /var/lib/gems/2.3.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/patches/jekyll/site.rb:114:in `each'
    from /var/lib/gems/2.3.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/patches/jekyll/site.rb:114:in `process_documents'
    from /var/lib/gems/2.3.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/hooks/process.rb:8:in `block in hook_process'
    from /var/lib/gems/2.3.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/hooks/process.rb:7:in `each'
    from /var/lib/gems/2.3.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/hooks/process.rb:7:in `hook_process'
    from /var/lib/gems/2.3.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/hooks/process.rb:3:in `block in <top (required)>'
    from /var/lib/gems/2.3.0/gems/jekyll-3.6.2/lib/jekyll/hooks.rb:100:in `block in trigger'
    from /var/lib/gems/2.3.0/gems/jekyll-3.6.2/lib/jekyll/hooks.rb:99:in `each'
    from /var/lib/gems/2.3.0/gems/jekyll-3.6.2/lib/jekyll/hooks.rb:99:in `trigger'
    from /var/lib/gems/2.3.0/gems/jekyll-3.6.2/lib/jekyll/site.rb:195:in `render'
    from /var/lib/gems/2.3.0/gems/jekyll-3.6.2/lib/jekyll/site.rb:73:in `process'
    from /var/lib/gems/2.3.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/patches/jekyll/site.rb:86:in `process_active_language'
    from /var/lib/gems/2.3.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/patches/jekyll/site.rb:70:in `process_language'
    from /var/lib/gems/2.3.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/patches/jekyll/site.rb:30:in `block (2 levels) in process'
    from /var/lib/gems/2.3.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/patches/jekyll/site.rb:29:in `fork'
    from /var/lib/gems/2.3.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/patches/jekyll/site.rb:29:in `block in process'
    from /var/lib/gems/2.3.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/patches/jekyll/site.rb:28:in `each'
    from /var/lib/gems/2.3.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/patches/jekyll/site.rb:28:in `process'
    from /var/lib/gems/2.3.0/gems/jekyll-3.6.2/lib/jekyll/command.rb:28:in `process_site'
    from /var/lib/gems/2.3.0/gems/jekyll-3.6.2/lib/jekyll/commands/build.rb:65:in `build'
    from /var/lib/gems/2.3.0/gems/jekyll-3.6.2/lib/jekyll/commands/build.rb:36:in `process'
    from /var/lib/gems/2.3.0/gems/jekyll-3.6.2/lib/jekyll/commands/serve.rb:42:in `block (3 levels) in init_with_program'
    from /var/lib/gems/2.3.0/gems/jekyll-3.6.2/lib/jekyll/commands/serve.rb:42:in `each'
    from /var/lib/gems/2.3.0/gems/jekyll-3.6.2/lib/jekyll/commands/serve.rb:42:in `block (2 levels) in init_with_program'
    from /var/lib/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
    from /var/lib/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
    from /var/lib/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
    from /var/lib/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
    from /var/lib/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
    from /var/lib/gems/2.3.0/gems/jekyll-3.6.2/exe/jekyll:15:in `<top (required)>'
    from /usr/local/bin/jekyll:22:in `load'
    from /usr/local/bin/jekyll:22:in `<main>'
                    done in 4.619 seconds.
untra commented 6 years ago

hmm... with the incremental documents may not have a defined output at the time the hook gets called.

The error is being thrown from here. Relativize urls is being called on a document with a null output. Document output's should not be null when this hook is called.

Any chance your jekyll project is accessible and on github? I'd be happy to clone it down and debug it further.

kerner1000 commented 6 years ago

Yes, sure, many thanks! https://kerner1000.github.io/

untra commented 6 years ago

So this is going to be embarrassing to admit... I haven't done ruby development in awhile, and I have a new computer. I've been meaning to get my ruby environment setup, so I figured I'd get my dev environment setup quickly so I could debug your project.

At this point I've spent four hours trying to get bundle install to work :fearful: I'm getting rolled by nokogiri, which is needed by jekyll to parse html / xml files. The damn thing refuses to install at all and I'm going insane here. I don't know what changed in the past few months of ruby development, but my ability to iterate quickly is currently gone :disappointed: I'll try again later this week, but I'm currently stuck at the moment.

If you have suggestions on good ruby development setups, I could use the advice.

untra commented 6 years ago

Are you seeing the NoMethodError when you run bundle exec jekyll serve? or does it only show up with the --incremental flag enabled?

kerner1000 commented 6 years ago

:smiley: no worries, its working anyways. It happens only with --incremental option. EDIT: cannot reproduce anymore.. :see_no_evil:

hvoigt commented 6 years ago

Just had this same issue after installing polyglot.

jekyll serve --incremental

/home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/patches/jekyll/site.rb:154:in `relativize_urls': undefined method `gsub!' for nil:NilClass (NoMethodError)
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/patches/jekyll/site.rb:115:in `block in process_documents'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/patches/jekyll/site.rb:114:in `each'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/patches/jekyll/site.rb:114:in `process_documents'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/hooks/process.rb:8:in `block in hook_process'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/hooks/process.rb:7:in `each'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/hooks/process.rb:7:in `hook_process'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/hooks/process.rb:3:in `block in <top (required)>'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-3.8.4/lib/jekyll/hooks.rb:103:in `block in trigger'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-3.8.4/lib/jekyll/hooks.rb:102:in `each'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-3.8.4/lib/jekyll/hooks.rb:102:in `trigger'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-3.8.4/lib/jekyll/site.rb:194:in `render'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-3.8.4/lib/jekyll/site.rb:71:in `process'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/patches/jekyll/site.rb:86:in `process_active_language'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/patches/jekyll/site.rb:70:in `process_language'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/patches/jekyll/site.rb:30:in `block (2 levels) in process'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/patches/jekyll/site.rb:29:in `fork'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/patches/jekyll/site.rb:29:in `block in process'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/patches/jekyll/site.rb:28:in `each'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-polyglot-1.3.1/lib/jekyll/polyglot/patches/jekyll/site.rb:28:in `process'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-3.8.4/lib/jekyll/command.rb:28:in `process_site'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-3.8.4/lib/jekyll/commands/build.rb:65:in `build'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-3.8.4/lib/jekyll/commands/build.rb:36:in `process'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-3.8.4/lib/jekyll/commands/serve.rb:93:in `block in start'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-3.8.4/lib/jekyll/commands/serve.rb:93:in `each'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-3.8.4/lib/jekyll/commands/serve.rb:93:in `start'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-3.8.4/lib/jekyll/commands/serve.rb:75:in `block (2 levels) in init_with_program'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
    from /home/hvoigt/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/jekyll-3.8.4/exe/jekyll:15:in `<top (required)>'
    from /home/hvoigt/.rbenv/versions/2.4.0/bin/jekyll:22:in `load'
    from /home/hvoigt/.rbenv/versions/2.4.0/bin/jekyll:22:in `<main>'
                    done in 0.113 seconds.

Once I ran just jekyll serve without the --incremental option the issue dissappeared and now even with --incremental it seems to work fine. Not sure what is cached where, but even a clean repository (git clean -xfd) does not help to have it resurface.

MPJHorner commented 5 years ago

Had exactly the same error as you, only just starting using --incremental few hours later I start seeing this error.

However, removing --incremental removed the problem, interestingly, if I add it back - it still isn't erroring...

However, when I run doctor I get this notification.

bundle exec jekyll doctor
Configuration file: /Users/User/Documents/GitHub/myApplication/_config.yml
jekyll 3.8.5 | Error:  undefined method `each' for nil:NilClass

Not sure if relate d(or how to fix this!

cmcnicholas commented 4 years ago

same issue with 4.0.0 of Jekyll

alexanderadam commented 4 years ago

I can reproduce it with any of my Jekyll projects. Simply add incremental: true to _config.yml and let the games begin.

Would in site.rb an early return in case of nil output do any harm?

For instance:

def relativize_urls(doc, regex)
  return if doc.output.nil?

  doc.output.gsub!(regex, "href=\"#{@baseurl}/#{@active_lang}/" + '\1"')
end

def relativize_absolute_urls(doc, regex, url)
  return if doc.output.nil?

  doc.output.gsub!(regex, "href=\"#{url}#{@baseurl}/#{@active_lang}/" + '\1"')
end
untra commented 4 years ago

yeah, this is a bug with incremental builds. Incremental builds use existing cached content that isn't available on the language forks for each build, when the site is fresh. This is a bug I keep punting on.

It has a workaround: Just run one jekyll build without incremental, and the languages from cached pages will be present. I know how necessary --incremental is for faster builds, especially on larger sites. one standard build will get it going I believe.

-sam

untra commented 4 years ago

@alexanderadam with your contribution merged in I cut a minor release. would you please try out version 1.3.3 and confirm noMethodError is still thrown on Document.output.nil , and when running with incremental jekyll builds?

alexanderadam commented 4 years ago

@untra I just tested it and this error is fixed with 1.3.3. Thank you! :+1:

I don't believe that this was the only thing necessary for incremental support, but it fixed at least this little error. :wink: