Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot load such file -- fog (LoadError) #401

Closed
guilpejon opened this issue Oct 7, 2017 · 9 comments
Closed

cannot load such file -- fog (LoadError) #401

guilpejon opened this issue Oct 7, 2017 · 9 comments

Comments

@guilpejon
Copy link

I have an application working with fog, carrierwave and AWS, and then I decided to switch to fog-aws.

All I did was change gem 'fog' to gem 'fog-aws' in my Gemfile, and I thought it would work right away, but now the server won't start.

The error seems to be happening inside my config.fog_credentials code in my carrierwave initialization file.

I tried adding require 'fog/aws' but it didn't worked, and it returns false when I try to do this require on the console as well, even though I can run this line Fog::Storage.new(provider: 'AWS', aws_access_key_id: 'aws_id', region: 'us-west-2', aws_secret_access_key: 'aws_secret') without a problem.

Am I doing something wrong?

Here is my carrierwave initialization file:

CarrierWave.configure do |config|
  if Rails.env.test?
    config.storage :file
    config.asset_host = 'http://localhost:3000'
  else
    config.fog_credentials = {
      provider:               ENV['FOG_PROVIDER'],
      aws_access_key_id:      ENV['AWS_ACCESS_KEY_ID'],
      aws_secret_access_key:  ENV['AWS_SECRET_ACCESS_KEY'],
      path_style:             ENV['FOG_PATH_STYLE']
    }
    config.storage = :fog
    config.fog_use_ssl_for_aws = true
    config.fog_directory  = ENV['FOG_DIRECTORY']
    config.fog_public     = true
    config.fog_attributes = { 'Cache-Control': 'max-age=315576000' }
    config.asset_host = 'https://s3.amazonaws.com/website'
  end
end

And here is the dump:

=> Booting Puma
=> Rails 5.1.4 application starting in development 
=> Run `rails server -h` for more startup options
Exiting
/Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require': cannot load such file -- fog (LoadError)
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `block in require'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/carrierwave-1.1.0/lib/carrierwave/uploader/configuration.rb:122:in `eager_load_fog'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/carrierwave-1.1.0/lib/carrierwave/uploader/configuration.rb:137:in `fog_credentials='
	from /Users/guilpejon/Desktop/codes/ruby_on_rails/website/config/initializers/carrierwave.rb:6:in `block in <top (required)>'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/carrierwave-1.1.0/lib/carrierwave/uploader/configuration.rb:159:in `configure'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/carrierwave-1.1.0/lib/carrierwave.rb:14:in `configure'
	from /Users/guilpejon/Desktop/codes/ruby_on_rails/website/config/initializers/carrierwave.rb:1:in `<top (required)>'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in `load'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in `block in load'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in `load'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/engine.rb:655:in `block in load_config_initializer'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/activesupport-5.1.4/lib/active_support/notifications.rb:168:in `instrument'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/engine.rb:654:in `load_config_initializer'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/engine.rb:612:in `block (2 levels) in <class:Engine>'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/engine.rb:611:in `each'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/engine.rb:611:in `block in <class:Engine>'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/initializable.rb:30:in `instance_exec'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/initializable.rb:30:in `run'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/initializable.rb:59:in `block in run_initializers'
	from /Users/guilpejon/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:228:in `block in tsort_each'
	from /Users/guilpejon/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
	from /Users/guilpejon/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
	from /Users/guilpejon/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:431:in `each_strongly_connected_component_from'
	from /Users/guilpejon/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/initializable.rb:48:in `each'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/initializable.rb:48:in `tsort_each_child'
	from /Users/guilpejon/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:415:in `call'
	from /Users/guilpejon/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:415:in `each_strongly_connected_component_from'
	from /Users/guilpejon/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:349:in `block in each_strongly_connected_component'
	from /Users/guilpejon/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:347:in `each'
	from /Users/guilpejon/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:347:in `call'
	from /Users/guilpejon/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:347:in `each_strongly_connected_component'
	from /Users/guilpejon/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:226:in `tsort_each'
	from /Users/guilpejon/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:205:in `tsort_each'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/initializable.rb:58:in `run_initializers'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/application.rb:353:in `initialize!'
	from /Users/guilpejon/Desktop/codes/ruby_on_rails/website/config/environment.rb:5:in `<top (required)>'
	from config.ru:3:in `require_relative'
	from config.ru:3:in `block in <main>'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/rack-2.0.3/lib/rack/builder.rb:55:in `instance_eval'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/rack-2.0.3/lib/rack/builder.rb:55:in `initialize'
	from config.ru:in `new'
	from config.ru:in `<main>'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/rack-2.0.3/lib/rack/builder.rb:49:in `eval'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/rack-2.0.3/lib/rack/builder.rb:49:in `new_from_string'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/rack-2.0.3/lib/rack/builder.rb:40:in `parse_file'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/rack-2.0.3/lib/rack/server.rb:319:in `build_app_and_options_from_config'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/rack-2.0.3/lib/rack/server.rb:219:in `app'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:24:in `app'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/rack-2.0.3/lib/rack/server.rb:354:in `wrapped_app'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:80:in `log_to_stdout'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:42:in `start'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:135:in `block in perform'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in `tap'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in `perform'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/command/base.rb:63:in `perform'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/command.rb:44:in `invoke'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
	from /Users/guilpejon/Desktop/codes/ruby_on_rails/website/bin/rails:9:in `require'
	from /Users/guilpejon/Desktop/codes/ruby_on_rails/website/bin/rails:9:in `<top (required)>'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
	from /Users/guilpejon/.rvm/gems/ruby-2.4.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
	from /Users/guilpejon/Desktop/codes/ruby_on_rails/website/bin/spring:15:in `require'
	from /Users/guilpejon/Desktop/codes/ruby_on_rails/website/bin/spring:15:in `<top (required)>'
	from bin/rails:3:in `load'
	from bin/rails:3:in `<main>'

@geemus
Copy link
Member

geemus commented Oct 17, 2017

That appears to be a somewhat older version of carrierwave, could you try updating to see if that solves the issue?

@guilpejon
Copy link
Author

Wasn't expecting this to work, but it did! I was using version 1.1.0 of carrierwave, and after updating it to 1.2.1 my code worked. Thanks @geemus

@geemus
Copy link
Member

geemus commented Oct 18, 2017

@guilpejon awesome, honestly I wasn't sure either, but thought it was worth a try before we dug in. Thanks for the update!

@lpradovera
Copy link

We are seeing the same problem with Carrierwave 1.2.1 - @guilpejon , what was the change you did exactly? Thanks!

@guilpejon
Copy link
Author

@lpradovera In my case I just updated Carrierwave to version 1.2.1 and I was able to start the server, but unfortunately I realized afterwards that fog-aws was still not working properly, so I returned to fog since I couldn't spend any more time debugging it. I will start a new issue here about it when I get the chance, and I suggest you to do the same.

@cameronbass
Copy link

cameronbass commented Oct 31, 2017


CarrierWave.configure do |config|
  if Rails.env.test?
    config.storage :file
    config.asset_host = 'http://localhost:3000'
  else
    config.storage = :fog
    config.fog_use_ssl_for_aws = true
    config.fog_directory  = ENV['FOG_DIRECTORY']
    config.fog_public     = true
    config.fog_attributes = { 'Cache-Control': 'max-age=315576000' }
    config.asset_host = 'https://s3.amazonaws.com/website'

    config.fog_credentials = {
      provider:               ENV['FOG_PROVIDER'],
      aws_access_key_id:      ENV['AWS_ACCESS_KEY_ID'],
      aws_secret_access_key:  ENV['AWS_SECRET_ACCESS_KEY'],
      path_style:             ENV['FOG_PATH_STYLE']
    }
  end
end

Your carrierwave.rb file needs to look like this. Your app needs to know that config.storage is == :fog before it gets to fog_credentials

@petrbela
Copy link

In our case, fog_provider had to be configured before fog_credentials. Thanks @cameronbass for the tip!

@archfish
Copy link

archfish commented Jun 11, 2018

just copy lib/fog-aws.rb to lib/fog.rb fix this
@lpradovera @guilpejon

CarrierWave.configure do |config|
  config.storage = Fog
  config.fog_directory  = 'mybucket'
  config.fog_public     = false
  config.fog_attributes = {'Cache-Control' => 'max-age=315576000'}

  config.fog_credentials = {
    provider:                'AWS',
    aws_access_key_id:       'access_key',
    aws_secret_access_key:   'secret_key',
    aws_signature_version:   2,
    endpoint:                'http://my.domain:7480',
    path_style:              true,
    region:                  'us-east-1'
  }
end

@fabOnReact
Copy link

config.fog_provider = 'fog/aws'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants