Heroku Deploy: URI::InvalidURIError: bad URI(is not URI?): ://user:[email protected]/dbname

1k Views Asked by At

I have a project with a Vue frontend and a rails backend. It's just a very simple API on the backend, no database or anything. It's working fine locally but now I want to deploy it on Heroku.

However, when I run it I get the following error.

-----> Detecting rake tasks
 !
 !     Could not detect rake tasks
 !     ensure you can run `$ bundle exec rake -P` against your app
 !     and using the production group of your Gemfile.
 !     rake aborted!
 !     URI::InvalidURIError: bad URI(is not URI?): ://user:[email protected]/dbname
  ...
  ...
/activerecord-6.0.2.1/lib/active_record/railties/databases.rake

Based on various SO posts/Heroku documentation, I have already tried:

  • bundle exec rake -P RAILS_ENV=production - everything looks ok
  • adding the rake dependency in Gemfile
  • removing the sqlite dependency in Gemfile
  • removing the BUNDLED WITH from Gemfile.lock

But still the same error.

I guess it's related to my database config, but I don't have any database on my project so this seems like an unnecessary task anyway. I tried commenting out railties from my Gemfile but it's still there as a dependency for other gems. When I deploy after making this change, it still hits the same task and fails.

Link to repo branch

2

There are 2 best solutions below

0
Chris A On BEST ANSWER

Needed to fully remove use of ActiveRecord from the project. As Max commented, in a new app this can be done by doing rails new app_name --skip-active-record --api, to do this for an existing project see this explanation

11
max On

Instead of require 'rails/all' which requires all the Railties including ActiveRecord you need to explicitily require the railties you want to use:

require File.expand_path('../boot', __FILE__)

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
# require "active_record/railtie"
# require "active_storage/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_mailbox/engine"
# require "action_text/engine"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"

module Draw
  class Application < Rails::Application
    # You don't need this nonsense since you don't even have config/application.yml
    #  ENV.update YAML.load_file('config/application.yml')[Rails.env] rescue {}
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de

    # Do not swallow errors in after_commit/after_rollback callbacks.
    # config.active_record.raise_in_transactional_callbacks = true
  end
end

If you don't want to use a ActiveRecord you can just get rid of /db and /config/database.yml.

You also don't need to add have gem 'rake' in your Gemfile as rails depends on it anyways.