custom_require.rb:36:in `require': no such file to load -- myapp(LoadError)
Check that you have the gems installed gem list
If not, install as usual gem install whatever
or if you want a specific version gem install whatever -v 1.2.3
Or if you have bundler in your project (ie Rails), it's just bundle install
If you have all the gems, then this is probably a local file, and you're probably coming from Ruby version < 1.9, you need to either fix your $LOAD_PATH
(which will depend on too many factors for me to explain here), or specify the full path to the file you want File.dirname(__FILE__) + '/myapp'
Otherwise, you need to give more info, like what version you used to be running, what myapp
is, and where it is in relation to your file.
Ruby 'require' error: cannot load such file
I just tried and it works with require "./tokenizer"
. Hope this helps.
`require': cannot load such file -- gemname non-rails app on server
When you use bundler to install gems outside if Ruby's global gem store, you also need to adapt the $LOAD_PATH
to include this custom location before you are able to require the gem.
The most common way to achieve this is to use bundle exec
. This command comes with bundler and adapts Ruby's $lOAD_PATH
to include the locations of all gems specified in the Gemfile
.
When you start your script as follows, Ruby should be able to find your gems (assuming your bin/run_control.rb
script is executable).
bundle exec bin/run_control.rb start
cannot load such file -- bundler/setup (LoadError)
It could be that there was a previous Ruby env installed on your system prior to your installation of 2.0? This might have had an existing GEM_PATH that lead to the /1.8 directory which the installation of version 2.0 simply kept.
The problem you where likely having, then, was that Passenger/Apache was looking in the /2.0 directory when in fact the gems were in the /1.8 directory. Your explicitly telling apache to use the /1.8 directory thus makes sense to fix the problem.
SetEnv GEM_HOME /usr/lib/ruby/gems/1.8
You might also try using the Ruby Version Manager to handle multiple Ruby envs.
Some things I found in Google:
- New to Ruby and am having trouble with LOAD_PATH
- http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices/
- http://guides.rubygems.org/faqs/
Could not find rails (= 0) amongst [] (Gem::LoadError)
I had to sudo gem install bundler
to make it work again.
strange inability to require config/boot after upgrading to ruby 1.9.2
Replacing line 2 of script/server with
require File.expand_path('../../config/boot', __FILE__)
works for me (taken from Rails 3)
Monkey patching Devise (or any Rails gem)
If you try to reopen a class, it's the same syntax as declaring a new class:
class DeviseController
end
If this code is executed before the real class declaration, it inherits from Object instead of extending the class declared by Devise. Instead I try to use the following
DeviseController.class_eval do
# Your new methods here
end
This way, you'll get an error if DeviseController
has not been declared. As a result, you'll probably end up with
require 'devise/app/controllers/devise_controller'
DeviseController.class_eval do
# Your new methods here
end
Heroku deployment - cannot load such file -- rake (LoadError)
[I've edited this original response to include a solution]
I have this exact issue too, with an open ticket with Heroku. No response yet, sadly but I found an answer elsewhere via a lucky hit in Google.
Context, for future reference and search engines
remote: -----> Detecting rake tasks
remote:
remote: !
remote: ! Could not detect rake tasks
remote: ! ensure you can run `$ bundle exec rake -P` against your app
remote: ! and using the production group of your Gemfile.
remote: ! /tmp/build_b8f358ab/bin/rake:3:in `require': cannot load such file -- rake (LoadError)
remote: ! from /tmp/build_b8f358ab/bin/rake:3:in `<main>'
remote: !
remote: /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/lib/language_pack/helpers/rake_runner.rb:106:in `load_rake_tasks!': Could not detect rake tasks (LanguagePack::Helpers::RakeRunner::CannotLoadRakefileError)
remote: ensure you can run `$ bundle exec rake -P` against your app
remote: and using the production group of your Gemfile.
remote: /tmp/build_b8f358ab/bin/rake:3:in `require': cannot load such file -- rake (LoadError)
remote: from /tmp/build_b8f358ab/bin/rake:3:in `<main>'
As you've doubtless already found, the suggested bundle exec rake -P
command above works fine with any Rails.env
setting locally. I, too, tried adding rake
to Gemfile
explicitly but this made no difference, nor did precompiling assets. Other things to note:
- All gems build successfully
- This deploy would prompt and update from Heroku-18 to the Heroku-20 platform; does yours?
- Rails 5 latest patch, but not Rails 6 yet
- Ruby 2.7.2
I don't use Spring so my bin/rake
is simpler:
#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
Rake.application.run
...and as with your more complex code, it's definitely the require 'rake'
that fails.
Solution
I can't take credit - it's this answer:
- https://stackoverflow.com/a/65604896
...that solved it, only you need to change from 2.1.2 to 2.1.4. Copy-pasting the above solution - again this is not my work, the credit belongs to the OP above:
gem uninstall bundler
gem install bundler --version '2.1.4' # If this doesn't work - see below
rm Gemfile.lock
bundle install
git add Gemfile.lock
git commit -m "Downgrade Bundler to match current Heroku version, so that deployments succeed"
git push heroku
This has solved the issue in my case. Seems like an utterly bizarre solution, but there you go.
If you don't seem to be unable to downgrade Bundler
In the comments on this answer, the OP notes:
Because Bundler version 2.2.10 was installed for me as the "default" I hadnt realised Gem bundler-2.1.4 cannot be uninstalled via gem uninstall bundler Using the cleanup_bundler script documented here enabled me to downgrade to v2.1.4 properly. This then did fix the rake problem.
$ gem uninstall bundler
=> Gem bundler-2.2.10 cannot be uninstalled because it is a default gem
StackOverflow prefer answers to be inline rather than linked externally as external links can break, so once again noting that credit goes to the article linked above:
From all the references I can find, the only way to remove it is to delete the
bundler-2.1.4.gemspec
file from the gem path. The following commands did the trick for me [...] I wrote a script for you:#!/usr/bin/env ruby
gempaths = `gem env gempath`.split(":")
gempaths.each do |gempath|
# lookup bundler-*.gemspec files and delete them
# this is the only way to completely cleanup default bundler
# Note: the bundler gemspecs' paths are different for CRuby and JRuby
Dir.glob(gempath.strip + "/specifications/**/bundler-*.gemspec").each { |p| File.delete(p) }
end
# Remember to make this file executable
...so hopefully if you save that as a .rb
file somewhere convenient, chmod u+x foo.rb
and ./foo.rb
- that might solve the problem.
Related Topics
Initialize a Ruby Class from an Arbitrary Hash, But Only Keys with Matching Accessors
Could Not Find Rake-10.1.0 in Any of the Sources
Rails: Get Values of Http Response
Positive Lookahead Doesn't Stop at First Occurrence
How to Perform Vector Addition in Ruby
Converting Binary Data to String in Ruby
How to Convert a Nested Hash into Xml Using Nokogiri
How to Run Rake with --Trace Within Capistrano
How to Reference a Method in Another Ruby Code File
Is There a Gem That Normalizes and Format Us Phone Numbers in Ruby
Detecting Overlapping Ranges in Ruby
Better Way to Write "Matching Balanced Parenthesis" Program in Ruby
Rails Helper - How to Get a Helper to Give Me a '<Br/>' (Or Other Markup)
Disable Rdoc and Ri Generation by Default for Rubygems 1.8.X