Rails deployment error: "NameError: uninitialized constant Devise (NameError)"

Hi, all! I’m new to fly.io when trying to deploy my app for the first time, I’ve been working through the errors and I am now stuck on this one:

fly deploy
==> Verifying app config
Validating /path/to/myproject/fly.toml
✓ Configuration is valid
--> Verified app config
==> Building image
Remote builder fly-builder-red-silence-2047 ready
Remote builder fly-builder-red-silence-2047 ready
==> Building image with Docker
--> docker host: 20.10.12 linux x86_64
[+] Building 4.0s (19/22)
 => [internal] load build definition from Dockerfile                                                    0.1s
 => => transferring dockerfile: 32B                                                                     0.1s
 => [internal] load .dockerignore                                                                       0.1s
 => => transferring context: 35B                                                                        0.1s
 => resolve image config for docker.io/docker/dockerfile:1                                              0.3s
 => CACHED docker-image://docker.io/docker/dockerfile:1@sha256:ac85f380a63b13dfcefa89046420e1781752bab  0.0s
 => [internal] load build definition from Dockerfile                                                    0.0s
 => [internal] load metadata for docker.io/library/ruby:3.2.2-slim                                      0.1s
 => [internal] load .dockerignore                                                                       0.0s
 => [internal] load build context                                                                       0.5s
 => => transferring context: 10.26kB                                                                    0.5s
 => [base 1/3] FROM docker.io/library/ruby:3.2.2-slim@sha256:b1b1636eb4e9d3499fc6166f54f7bb96d792e005b  0.0s
 => CACHED [base 2/3] WORKDIR /rails                                                                    0.0s
 => CACHED [base 3/3] RUN gem update --system --no-document &&     gem install -N bundler               0.0s
 => CACHED [stage-2 1/4] RUN apt-get update -qq &&     apt-get install --no-install-recommends -y curl  0.0s
 => CACHED [build 1/7] RUN apt-get update -qq &&     apt-get install --no-install-recommends -y build-  0.0s
 => CACHED [build 2/7] COPY Gemfile.lock ./                                                             0.0s
 => CACHED [build 3/7] COPY Gemfile ./                                                                  0.0s
 => CACHED [build 4/7] RUN bundle install &&     bundle exec bootsnap precompile --gemfile &&     rm -  0.0s
 => [build 5/7] COPY --link . .                                                                         0.0s
 => [build 6/7] RUN bundle exec bootsnap precompile app/ lib/                                           1.0s
 => ERROR [build 7/7] RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile                         1.7s
------
 > [build 7/7] RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile:
1.671 bin/rails aborted!
1.672 NameError: uninitialized constant Devise (NameError)
1.672
1.672 Devise.setup do |config|
1.672 ^^^^^^
1.672 /rails/config/initializers/devise.rb:12:in `<main>'
1.672 /rails/config/environment.rb:5:in `<main>'
1.673 Tasks: TOP => environment
1.673 (See full trace by running task with --trace)
------
Error: failed to fetch an image or build from source: error building: failed to solve: executor failed running [/bin/sh -c SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile]: exit code: 1

The app runs fine locally, it seems like the issue is in one of the bundling steps in the dockerfile, but I have worked through several solutions suggested here and elsewhere online.

Can you post your Gemfile?

Here are the contents of my gemfile:

source "https://rubygems.org"

ruby "3.2.2"

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.1.2"

# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "sprockets-rails"

# Use sqlite3 as the database for Active Record
# gem "sqlite3", "~> 1.4"

# Use the Puma web server [https://github.com/puma/puma]
gem "puma", ">= 5.0"

# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem "importmap-rails"

# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem "turbo-rails"

# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem "stimulus-rails"

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder"

# Use Redis adapter to run Action Cable in production
gem "redis", ">= 4.0.1"

gem 'net-http'

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"

# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ windows jruby ]

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

group :development, :test do
  # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
  gem "debug", platforms: %i[ mri windows ]
  gem 'devise'
  # WIP for debugging: the following were added perhttps://dev.to/abstractart/easy-way-to-setup-debugger-and-autocomplete-for-ruby-in-visual-studio-code-2gcc -sm
  # gem "ruby-debug-ide", require: false
  # gem "debase", require: false
  # gem 'solargraph', require: false
end

group :development do
  # Use console on exceptions pages [https://github.com/rails/web-console]
  gem "web-console"
  # gem 'letter_opener'
  gem 'letter_opener', '~> 1.7', group: :development

  gem 'letter_opener_web'
  # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
  # gem "rack-mini-profiler"

  # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
  # gem "spring"
end

group :test do
  # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
  gem "capybara"
  gem "selenium-webdriver"
end

gem "dockerfile-rails", ">= 1.6", :group => :development

gem "pg", "~> 1.5"

It looks like you need devise in production, not just :development and :test. Move that line outside of the group; run bundle update; then fly deploy.

That makes perfect sense and took care of the issue! Thank you very much!

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