0

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)

JohnP
  • 1,229
  • 6
  • 24
  • could you add the `gem install publishr` and do bundle install instead of bundle update? – neo May 06 '19 at 13:31
  • Thanks for the pointer, @neo. I'd already tried `gem install publishr` but that wasn't enough. Check my answer below - I had to require both publishr and a specific version of rubyzip. – JohnP May 06 '19 at 16:03

2 Answers2

0

bootsnap may have a role to play in all of this since it messes with the startup of Rails. Try making sure all spring processes are cleaned up ps -ef | grep spring. Remove bootsnap gem and bundle install. Then try to start the server again rails s.

Derek Wright
  • 1,452
  • 9
  • 11
  • Thanks for the advice, @ddubs. I think I've sorted it without removing bootsnap (see separate answer) but I'll certainly bear the advice in mind for future issues! – JohnP May 06 '19 at 16:00
0

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!

JohnP
  • 1,229
  • 6
  • 24
  • That is the issue given the fact that the line referenced shows you it need `publishr` but for some reason the maintainer of `docx_converter` did not add it as a dependency. All that being said do you really want to use a gem that has not had any substantial change made to it in 5 years? – engineersmnky May 06 '19 at 18:21
  • Ideally not, @engineersmnky, but there don't seem to be many choices! Have you come across any other ways to access the content of Word files in a Rails app? (I just need to extract the text content, ideally with basic formatting, for further processing.) – JohnP May 07 '19 at 06:36
  • The formatting part is the main issue. To grab just the text `docx` or preferably `docripper` can perform those tasks for you. – engineersmnky May 07 '19 at 13:03
  • Thanks, @engineersmnky - docx is doing the job nicely now for me, but I'll check out docripper too. – JohnP May 07 '19 at 18:05