Search code examples
ruby-on-railsrubygemsruby-on-rails-5publisher

Problem running 'rails s' after adding gem docx_converter


TL;DR:

I should have used the docx gem and not the (older) docx_converter. This seems much more compatible with Rails 5.2.


I'm learning rails and have a working application. However, when I add the gem docx_converter to my Gemfile (so I can convert Word files to markdown to work on further), the server fails to launch.

The application has three models: Company, which has_many Users, which has_many Projects. (Users is controlled by Devise, and Company has_many Projects through Users.) When a user creates a project, they can upload a file to that project using active_storage, and it's stored on disk in my dev environment (which is what I'm concerned with here).

I have no problem with any of the above - I can create users and projects, and add and remove files from the projects.

However, if I add gem 'docx_converter' to my Gemfile and run bundle update, I can no longer run the rails server. Immediately before this action, all is fine. Immediately after, the server won't run and the traceback (last few lines) is:

    10: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
     9: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/docx_converter-1.0.0/lib/docx_converter.rb:18:in `<main>'
     8: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
     7: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
     6: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
     5: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:26:in `require'
     4: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:40:in `rescue in require'
     3: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
     2: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:89:in `register'
     1: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require': cannot load such file -- publishr (LoadError)

Given the references to bootsnap, I tried removing this from the Gemfile and config/boot.rb, but that led to the same error in a different place but about the same thing (publishr):

    10: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:65:in `require'
     9: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:65:in `each'
     8: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:76:in `block in require'
     7: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:76:in `each'
     6: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:81:in `block (2 levels) in require'
     5: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:81:in `require'
     4: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/docx_converter-1.0.0/lib/docx_converter.rb:18:in `<top (required)>'
     3: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
     2: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
     1: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
/Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require': cannot load such file -- publishr (LoadError)

I've tried installing publishr via "gem install publishr" but it doesn't help.

My Gemfile is:

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.2'

gem 'rails', '~> 5.2.3'
gem 'puma', '~> 3.11'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
gem 'bcrypt', '~> 3.1.7'
gem 'bootsnap', '>= 1.1.0', require: false

# Manually added gems
gem 'will_paginate', '~> 3.1.6'
gem 'devise', '~> 4.6.2'
gem 'cancancan', '~>3.0.1'
gem 'docx_converter', '~>1.0.0'

group :development, :test do
  gem 'sqlite3'
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  gem 'faker', '~> 1.7.3'
end

group :development do
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

There seems to be an issue with this gem and Rails 5.2.3 but does anyone know what's going on here and how I could get it working? (Or alternatively, a different gem for converting a Word docx file to something usable)


Solution

  • After a certain amount of diving down rabbit holes, I found that I needed to explicitly require two extra gems for docx_converter to work, and also had to lock the version of one of them.

    gem 'publishr'
    gem 'rubyzip', '~>0.9.9'
    gem 'docx_converter', '~>1.0.0'
    

    I've not exhaustively tested the functionality, but at least the server now starts! Thanks for the suggestions, everyone!

    Edit

    Even after getting the server running, I had problems with this gem - as @engineersmnky said, it's pretty old and poorly documented. So I've swapped to the docx gem, which doesn't try to do as much but does seem (a) to load without problems on Rails 5.2 and (b) to work!