Skip to content

NameError: uninitialized constant Rack::File in Rails 8.1 (Rack 3 compatibility) #659

@vladlozzi

Description

@vladlozzi

When using rack-mini-profiler with Rails 8.1.2 and Rack 3.x, a NameError is triggered when the browser attempts to load the profiler resources (e.g., includes.js).

Error Message:

Plaintext

Rack app ("GET /mini-profiler-resources/includes.js" - (::1)): #<NameError: uninitialized constant Rack::File>
Did you mean? Rack::Files
Environment:

Rails version: 8.1.2

Rack version: 3.2.4

Ruby version: 3.4.2

rack-mini-profiler version: 3.3.1 (latest)

Context: In Rack 3, Rack::File was renamed to Rack::Files. It seems the asset handler within the gem still references the old constant name, which has been removed in the latest Rack specification.

While the app remains functional, it clutters the development logs with NameError exceptions on every page load where the profiler is active.

Workaround used: Manually aliasing the constant in config/application.rb:

Ruby

initializer :fix_rack_file_constant, before: :build_middleware_stack do
require "rack"
Rack.const_set(:File, Rack::Files) unless Rack.const_defined?(:File)
end

Suggested Fix: Update the resource server/asset handler to check for Rack::Files (Rack 3+) or fallback to Rack::File (Rack 2.x).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions