Why I am getting Could not find multi_json-1.3.1 i

2020-06-03 05:03发布

问题:

I have a simple Rails application I want to deploy to Heroku. When I run the below command

git push heroku master

The below error message is displayed.

 Could not find multi_json-1.3.1 in any of the sources
 !
 ! Failed to install gems via Bundler.
 !
 ! Heroku push rejected, failed to compile Ruby/rails app

Here is my Gemfile

 gem 'rails', '3.2.3'
 gem 'pg'
 group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'therubyracer', :platform => :ruby
  gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'

回答1:

Delete the Gemfile.lock file, and run bundle install. This works for me!



回答2:

I saw a series of these errors for different gems in spite of the fact I knew these gems were available (e.g. gem list -r <gem> showed them, including version; browsing rubygems.org showed the version I needed was there and hadn't been yanked etc) and I had a source set (I even set 6 different sources to be sure).

It turned out my problem was I had git stashed before leaving a feature branch to pull the latest on develop and forgotten to pop the stash afterwards, which was a problem because I had changed my .rvmrc and not committed the change (to use a newer ruby than our production did).

Because my .rvmrc specified a gemset for the project, stashing it meant I was suddenly bundling against a gemset that was missing a whole bunch of gems in my Gemfile.lock and for reasons I don't understand Bundler assumes if the gem is in Gemfile.lock it's already installed and it doesn't look it up remotely.

So just in case anyone else faces this incredibly frustrating corner case I thought I'd write it up here.



回答3:

If you are using Capistrano to do your deployments and you mysteriously get "Could not find multi_json-1.7.2 in any of the sources", ensure you have require "bundler/capistrano" at the top of your config/deploy.rb.



回答4:

In my case, I was lacking

source 'https://rubygems.org'

in Gemfile. My suspicion is that old versions of bundler can operate without a source being mentioned, but newer versions can't.



回答5:

For me this was caused because Pow (local rack server) was not using the correct RVM ruby version/gemset.

Fixed by adding the following .powrc:

# based on https://coderwall.com/p/pkj39a
if [ -f "$rvm_path/scripts/rvm" ] && [ -f ".ruby-version" ] && [ -f ".ruby-gemset" ]; then
  source "$rvm_path/scripts/rvm"
  rvm use `cat .ruby-version`@`cat .ruby-gemset`
fi

Source: https://coderwall.com/p/pkj39a



回答6:

I have solved it by the following steps.

Removed Gemfile.lock
bundle install

The cause of the problem is initially my Gemfile.lock has multi_json-1.3.1

Now it has the version multi_json-1.3.2