2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Rails Tutorial 6`require': no implicit conversion of String into Integer (TypeError)

Last updated at Posted at 2020-05-15

そもそもbootsnapとは?
https://qiita.com/Daniel_Nakano/items/aadeaa7ae4e227b73878

手取り早く、解決したい方へ

console.
gem list bootsnap
// bootsnap (1.4.6, 1.4.4)

と、バージョン差異が出ていたら、

console.
gem uninstall bootsnap --version {指定したい方}

と、必要のないバージョンを削除して終わりです。

そもそも

ローカルで開発する際、Gemfileをいじると思います。
私の場合、

console.
user-no-MacBook-Pro:user$ bundle update
user-no-MacBook-Pro:user$ bundle install --without production
...
Bundle complete! 31 Gemfile dependencies, 108 gems now installed.
Gems in the group production were not installed.
Bundled gems are installed into `./.`

と、ここまで良かったのですが、

console.
user-no-MacBook-Pro:user$ rails s

で、サーバーを起動しようとした際、

console.
Traceback (most recent call last):
	24: from bin/rails:3:in `<main>'
	23: from bin/rails:3:in `require_relative'
	22: from /Users/user/tutorial/config/boot.rb:4:in `<top (required)>'
	21: from /Users/user/tutorial/config/boot.rb:4:in `require'
	20: from /Users/user/tutorial/ruby/2.7.0/gems/bootsnap-1.4.4/lib/bootsnap/setup.rb:30:in `<top (required)>'
	19: from /Users/user/tutorial/ruby/2.7.0/gems/bootsnap-1.4.4/lib/bootsnap.rb:30:in `setup'
	18: from /Users/user/tutorial/ruby/2.7.0/gems/bootsnap-1.4.4/lib/bootsnap/compile_cache.rb:9:in `setup'
	17: from /Users/user/tutorial/ruby/2.7.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:48:in `require_relative'
	16: from /Users/user/tutorial/ruby/2.7.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
	15: from /Users/user/tutorial/ruby/2.7.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:291:in `load_dependency'
	14: from /Users/user/tutorial/ruby/2.7.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
	13: from /Users/user/tutorial/ruby/2.7.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
	12: from /Users/user/tutorial/ruby/2.7.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
	11: from /Users/user/tutorial/ruby/2.7.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
	10: from /Users/user/tutorial/ruby/2.7.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
	 9: from /Users/user/tutorial/ruby/2.7.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
	 8: from /Users/user/tutorial/ruby/2.7.0/gems/bootsnap-1.4.4/lib/bootsnap/compile_cache/iseq.rb:1:in `<top (required)>'
	 7: from /Users/user/tutorial/ruby/2.7.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
	 6: from /Users/user/tutorial/ruby/2.7.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:291:in `load_dependency'
	 5: from /Users/user/tutorial/ruby/2.7.0/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
	 4: from /Users/user/tutorial/ruby/2.7.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
	 3: from /Users/user/tutorial/ruby/2.7.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/user/tutorial/ruby/2.7.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
	 1: from /Users/user/tutorial/ruby/2.7.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/user/tutorial/ruby/2.7.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require': no implicit conversion of String into Integer (TypeError)

と、グアっとエラーが出ていました。

何をしてこうなったか

・bundle install前に、元々Gemfileは存在していた。
・その元々のGemfileは、bundle installやらなんやらしていてRailsと繋がっていた。
・新たなGemfileで諸々バージョンなども変更されていてbundle update → bundle installしようとしたら、上記のエラーが出た。

元々のGemfile

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

ruby '2.7.1'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '~> 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  # Easy installation and use of web drivers to run system tests with browsers
  gem 'webdrivers'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

新たなGemfile

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

gem 'rails',                      '6.0.0'
gem 'aws-sdk-s3',                 '1.46.0', require: false
gem 'image_processing',           '1.9.3'
gem 'mini_magick',                '4.9.5'
gem 'active_storage_validations', '0.8.2'
gem 'bcrypt',                     '3.1.13'
gem 'faker',                      '2.1.2'
gem 'will_paginate',              '3.1.8'
gem 'bootstrap-will_paginate',    '1.0.0'
gem 'bootstrap-sass',             '3.4.1'
gem 'puma',                       '3.12.1'
gem 'sass-rails',                 '5.1.0'
gem 'webpacker',                  '4.0.7'
gem 'turbolinks',                 '5.2.0'
gem 'jbuilder',                   '2.9.1'
gem 'bootsnap',                   '1.4.4', require: false // ←errorで止まってしまう

group :development, :test do
  gem 'sqlite3', '1.4.1'
  gem 'byebug',  '11.0.1', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  gem 'web-console',           '4.0.1'
  gem 'listen',                '3.1.5'
  gem 'spring',                '2.1.0'
  gem 'spring-watcher-listen', '2.0.1'
end

group :test do
  gem 'capybara',                 '3.28.0'
  gem 'selenium-webdriver',       '3.142.4'
  gem 'webdrivers',               '4.1.2'
  gem 'rails-controller-testing', '1.0.4'
  gem 'minitest',                 '5.11.3'
  gem 'minitest-reporters',       '1.3.8'
  gem 'guard',                    '2.16.2'
  gem 'guard-minitest',           '2.4.6'
end

group :production do
  gem 'pg', '1.1.4'
end

解決策

問題は、bootsnapのバージョン差異にあります。

Gemfile.
// 元々
gem 'bootsnap',                   '>= 1.4.2', require: false

// 新規
gem 'bootsnap',                   '1.4.4'

なので、この場合は元々のbootsnapのバージョンを指定し直す事でエラーが解決できます。

Gemfile.
gem 'bootsnap',                   '>= 1.4.2', require: false

と、再指定して

console.
user-no-MacBook-Pro:user$ bundle update bootsnap
...
Using bootsnap 1.4.6 (was 1.4.4)
...
Bundle updated!
Gems in the group production were not updated.

user-no-MacBook-Pro:user$ rails s
=> Booting Puma
=> Rails 6.0.0 application starting in development 
=> Run `rails server --help` for more startup options

となれば、成功です。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?