ERROR [build 6/6] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precom

I’m trying to deploy a sample rails project and have encountered the following error:

ERROR [build 6/6] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precom

These are the logs i get after run fly deploy

 => ERROR [build 6/6] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precom  1.2s
------
 > [build 6/6] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile:
#16 1.150 rails aborted!
#16 1.150 NameError: uninitialized constant LetterOpenerWeb
#16 1.150 /rails/config/routes.rb:5:in `block in <main>'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/actionpack-7.0.4.3/lib/action_dispatch/routing/route_set.rb:428:in `instance_exec'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/actionpack-7.0.4.3/lib/action_dispatch/routing/route_set.rb:428:in `eval_block'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/actionpack-7.0.4.3/lib/action_dispatch/routing/route_set.rb:410:in `draw'
#16 1.150 /rails/config/routes.rb:1:in `<main>'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/application/routes_reloader.rb:50:in `load'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/application/routes_reloader.rb:50:in `block in load_paths'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/application/routes_reloader.rb:50:in `each'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/application/routes_reloader.rb:50:in `load_paths'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/application/routes_reloader.rb:24:in `reload!'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/application/routes_reloader.rb:38:in `block in updater'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/file_update_checker.rb:83:in `execute'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/application/routes_reloader.rb:13:in `execute'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/application/finisher.rb:158:in `block in <module:Finisher>'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/initializable.rb:32:in `instance_exec'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/initializable.rb:32:in `run'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/initializable.rb:61:in `block in run_initializers'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/initializable.rb:60:in `run_initializers'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/application.rb:372:in `initialize!'
#16 1.150 /rails/config/environment.rb:5:in `<main>'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/zeitwerk-2.6.7/lib/zeitwerk/kernel.rb:38:in `require'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/application.rb:348:in `require_environment!'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/application.rb:511:in `block in run_tasks_blocks'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/sprockets-rails-3.4.2/lib/sprockets/rails/task.rb:61:in `block (2 levels) in define'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/commands/rake/rake_command.rb:18:in `perform'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/command.rb:51:in `invoke'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.3/lib/rails/commands.rb:18:in `<main>'
#16 1.150 /rails/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
#16 1.150 Tasks: TOP => environment
#16 1.150 (See full trace by running task with --trace)
------
Error failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile]: exit code: 1

I know it similar to this issue, However, the solution is not resolving my issues.

Need a solution for someone who is just getting started with rails.

Assuming this matches GitHub - fgrehm/letter_opener_web: A web interface for browsing Ruby on Rails sent emails, what does line 5 in config/routes.rb contain? In particular, does it end in if Rails.env.development?

This is my config/routes.rb

Rails.application.routes.draw do
  # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

  # If you have a dedicated config/environments/staging.rb
  mount LetterOpenerWeb::Engine, at: "/mail"
  # Defines the root path route ("/")
  root "root#index"
  post "/", to: "root#send_email"
end

If your Gemfile looks like this:

group :development do
  gem 'letter_opener_web', '~> 2.0'
end

Then line 5 needs to look like this:

mount LetterOpenerWeb::Engine, at: "/mail" if Rails.env.development?

Deployment success, but ran into new issues

2023-04-06T12:48:15.443 app[5683d399c1e728] ams [info] F, [2023-04-06T12:48:15.443753 #512] FATAL -- : [ebc65ee7-a0d3-4df6-b1be-7660b80e4f7a]

2023-04-06T12:48:15.443 app[5683d399c1e728] ams [info] [ebc65ee7-a0d3-4df6-b1be-7660b80e4f7a] RuntimeError (Invalid delivery method :letter_opener_web):

2023-04-06T12:48:15.443 app[5683d399c1e728] ams [info] [ebc65ee7-a0d3-4df6-b1be-7660b80e4f7a]

2023-04-06T12:48:15.443 app[5683d399c1e728] ams [info] [ebc65ee7-a0d3-4df6-b1be-7660b80e4f7a] app/mailers/user_mailer.rb:5:in `send_email'

2023-04-06T12:48:15.443 app[5683d399c1e728] ams [info] [ebc65ee7-a0d3-4df6-b1be-7660b80e4f7a] app/controllers/root_controller.rb:3:in `send_email'

Is this something you only want on your development machine? If so, you may need to add if Rails.env.development?. If not, you may need to remove this from config/routes.rb and move the gem line in your Gemfile outside of the `group :development do’ block.

1 Like

Perfect, It worked!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.