primer / view_components

ViewComponents for the Primer Design System
https://primer.style/components/
MIT License
451 stars 114 forks source link

uninitialized constant Primer::FormHelper #3104

Open AlexeyMatskevich opened 1 week ago

AlexeyMatskevich commented 1 week ago

Can't reproduce the installation from https://primer.style/guides/rails

  1. Install the primer_view_components gem and @primer/view-components packages

    gem install rails
    rails -v
    => Rails 7.2.1
    rails new test_app -d postgresql -j bun --skip-active-record --skip-active-storage -a propshaft -T --force
    bundle add primer_view_components # ~> 0.34 version
    bun add @primer/view-components # ^0.34.0 version
    bun add @primer/css ^21.3.6 version
    bun add @primer/primitives ^9.1.2 version
  2. Add the following lines to the very bottom of config/application.rb:

    require "view_component"
    require "primer/view_components"
  3. Add your node_modules/ directory to Propshaft's load path by adding the following line to config/application.rb:

    config.assets.paths << Rails.root.join("node_modules") My file:

    # application.rb
    require_relative "boot"
    
    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 "rails/test_unit/railtie"
    require "view_component"
    require "primer/view_components"
    require "primer/view_components/engine"
    
    # Require the gems listed in Gemfile, including any gems
    # you've limited to :test, :development, or :production.
    Bundler.require(*Rails.groups)
    
    module Nextexaminer
      class Application < Rails::Application
        # Initialize configuration defaults for originally generated Rails version.
        config.load_defaults 7.2
    
        # Please, add to the `ignore` list any other `lib` subdirectories that do
        # not contain `.rb` files, or that should not be reloaded or eager loaded.
        # Common ones are `templates`, `generators`, or `middleware`, for example.
        config.autoload_lib(ignore: %w[assets tasks])
    
        # Configuration for the application, engines, and railties goes here.
        #
        # These settings can be overridden in specific environments using the files
        # in config/environments, which are processed later.
        #
        # config.time_zone = "Central Time (US & Canada)"
        # config.eager_load_paths << Rails.root.join("extras")
    
        # Don't generate system test files.
        config.generators.system_tests = nil
    
        # Load node_modules
        config.assets.paths << Rails.root.join("node_modules")
      end
    end
  4. Add the following inside the tags in app/views/layouts/application.html.erb. These lines request primer_view_component's JavaScript code, shared CSS styles from @primer/css, primer_view_component's CSS styles, and a bunch of CSS variables from @primer/primitives. Notice we're also pulling in several color themes named "light" and "dark." The full list of supported themes is available in the Primer CSS documentation.

    <%= stylesheet_link_tag "@primer/css/dist/primer.css", "data-turbo-track": "reload" %>
    <%= stylesheet_link_tag "@primer/view-components/app/assets/styles/primer_view_components.css", "data-turbo-track": "reload" %>
    <%= stylesheet_link_tag "@primer/primitives/dist/css/primitives.css", "data-turbo-track": "reload" %>
    <%= stylesheet_link_tag "@primer/primitives/dist/css/functional/themes/light.css", "data-turbo-track": "reload" %>
    <%= stylesheet_link_tag "@primer/primitives/dist/css/functional/themes/dark.css", "data-turbo-track": "reload" %>
    
    <%= javascript_include_tag "@primer/view-components/app/assets/javascripts/primer_view_components.js", "data-turbo-track": "reload" %>

    My file:

    # application.html.erb
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <title><%= content_for(:title) || "Nextexaminer" %></title>
        <meta name="viewport" content="width=device-width,initial-scale=1">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <%= csrf_meta_tags %>
        <%= csp_meta_tag %>
    
        <%= yield :head %>
    
        <link rel="manifest" href="/manifest.json">
        <link rel="icon" href="/icon.png" type="image/png">
        <link rel="icon" href="/icon.svg" type="image/svg+xml">
        <link rel="apple-touch-icon" href="/icon.png">
        <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
        <%= javascript_include_tag "application", "data-turbo-track": "reload", type: "module" %>
        <%= stylesheet_link_tag "@primer/css/dist/primer.css", "data-turbo-track": "reload" %>
        <%= stylesheet_link_tag "@primer/view-components/app/assets/styles/primer_view_components.css", "data-turbo-track": "reload" %>
        <%= stylesheet_link_tag "@primer/primitives/dist/css/primitives.css", "data-turbo-track": "reload" %>
        <%= stylesheet_link_tag "@primer/primitives/dist/css/functional/themes/light.css", "data-turbo-track": "reload" %>
        <%= stylesheet_link_tag "@primer/primitives/dist/css/functional/themes/dark.css", "data-turbo-track": "reload" %>
    
        <%= javascript_include_tag "@primer/view-components/app/assets/javascripts/primer_view_components.js", "data-turbo-track": "reload" %>
      </head>
    
      <body data-color-mode="light" data-light-theme="light" data-dark-theme="dark">
        <%= render 'layouts/sidebar' %>
        <div>
          <%= yield %>
        </div>
      </body>
    </html>

    My result:

    bin/dev
    01:47:51 web.1  | started with pid 493864
    01:47:51 js.1   | started with pid 493865
    01:47:51 js.1   | $ bun bun.config.js --watch
    01:47:52 web.1  | => Booting Puma
    01:47:52 web.1  | => Rails 7.2.1 application starting in development 
    01:47:52 web.1  | => Run `bin/rails server --help` for more startup options
    01:47:52 web.1  | Exiting
    01:47:52 web.1  | /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/primer_view_components-0.34.0/lib/primer/view_components/engine.rb:52:in `block (2 levels) in <class:Engine>': uninitialized constant Primer::FormHelper (NameError)
    01:47:52 web.1  | 
    01:47:52 web.1  |           helper Primer::FormHelper
    01:47:52 web.1  |                        ^^^^^^^^^^^^
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/activesupport-7.2.1/lib/active_support/lazy_load_hooks.rb:97:in `class_eval'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/activesupport-7.2.1/lib/active_support/lazy_load_hooks.rb:97:in `block in execute_hook'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/activesupport-7.2.1/lib/active_support/lazy_load_hooks.rb:87:in `with_execution_control'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/activesupport-7.2.1/lib/active_support/lazy_load_hooks.rb:92:in `execute_hook'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/activesupport-7.2.1/lib/active_support/lazy_load_hooks.rb:62:in `block in on_load'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/activesupport-7.2.1/lib/active_support/lazy_load_hooks.rb:61:in `each'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/activesupport-7.2.1/lib/active_support/lazy_load_hooks.rb:61:in `on_load'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/primer_view_components-0.34.0/lib/primer/view_components/engine.rb:46:in `block in <class:Engine>'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/railties-7.2.1/lib/rails/initializable.rb:32:in `instance_exec'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/railties-7.2.1/lib/rails/initializable.rb:32:in `run'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/railties-7.2.1/lib/rails/initializable.rb:61:in `block in run_initializers'
    01:47:52 web.1  |       from /nix/store/2vg3asd3rmhng3wqvp781a1q5dhrr4yn-ruby-3.3.4/lib/ruby/3.3.0/tsort.rb:231:in `block in tsort_each'
    01:47:52 web.1  |       from /nix/store/2vg3asd3rmhng3wqvp781a1q5dhrr4yn-ruby-3.3.4/lib/ruby/3.3.0/tsort.rb:353:in `block (2 levels) in each_strongly_connected_component'
    01:47:52 web.1  |       from /nix/store/2vg3asd3rmhng3wqvp781a1q5dhrr4yn-ruby-3.3.4/lib/ruby/3.3.0/tsort.rb:434:in `each_strongly_connected_component_from'
    01:47:52 web.1  |       from /nix/store/2vg3asd3rmhng3wqvp781a1q5dhrr4yn-ruby-3.3.4/lib/ruby/3.3.0/tsort.rb:352:in `block in each_strongly_connected_component'
    01:47:52 web.1  |       from /nix/store/2vg3asd3rmhng3wqvp781a1q5dhrr4yn-ruby-3.3.4/lib/ruby/3.3.0/tsort.rb:350:in `each'
    01:47:52 web.1  |       from /nix/store/2vg3asd3rmhng3wqvp781a1q5dhrr4yn-ruby-3.3.4/lib/ruby/3.3.0/tsort.rb:350:in `call'
    01:47:52 web.1  |       from /nix/store/2vg3asd3rmhng3wqvp781a1q5dhrr4yn-ruby-3.3.4/lib/ruby/3.3.0/tsort.rb:350:in `each_strongly_connected_component'
    01:47:52 web.1  |       from /nix/store/2vg3asd3rmhng3wqvp781a1q5dhrr4yn-ruby-3.3.4/lib/ruby/3.3.0/tsort.rb:229:in `tsort_each'
    01:47:52 web.1  |       from /nix/store/2vg3asd3rmhng3wqvp781a1q5dhrr4yn-ruby-3.3.4/lib/ruby/3.3.0/tsort.rb:208:in `tsort_each'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/railties-7.2.1/lib/rails/initializable.rb:60:in `run_initializers'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/railties-7.2.1/lib/rails/application.rb:435:in `initialize!'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/Sft/nextexaminer/config/environment.rb:5:in `<main>'
    01:47:52 web.1  |       from config.ru:3:in `require_relative'
    01:47:52 web.1  |       from config.ru:3:in `block (2 levels) in <main>'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/rack-3.1.7/lib/rack/builder.rb:108:in `eval'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/rack-3.1.7/lib/rack/builder.rb:108:in `new_from_string'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/rack-3.1.7/lib/rack/builder.rb:97:in `load_file'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/rack-3.1.7/lib/rack/builder.rb:67:in `parse_file'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/rackup-2.1.0/lib/rackup/server.rb:354:in `build_app_and_options_from_config'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/rackup-2.1.0/lib/rackup/server.rb:263:in `app'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/rackup-2.1.0/lib/rackup/server.rb:424:in `wrapped_app'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/railties-7.2.1/lib/rails/commands/server/server_command.rb:76:in `log_to_stdout'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/railties-7.2.1/lib/rails/commands/server/server_command.rb:36:in `start'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/railties-7.2.1/lib/rails/commands/server/server_command.rb:145:in `block in perform'
    01:47:52 web.1  |       from <internal:kernel>:90:in `tap'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/railties-7.2.1/lib/rails/commands/server/server_command.rb:136:in `perform'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/thor-1.3.2/lib/thor/command.rb:28:in `run'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/thor-1.3.2/lib/thor/invocation.rb:127:in `invoke_command'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/railties-7.2.1/lib/rails/command/base.rb:178:in `invoke_command'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/thor-1.3.2/lib/thor.rb:538:in `dispatch'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/railties-7.2.1/lib/rails/command/base.rb:73:in `perform'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/railties-7.2.1/lib/rails/command.rb:71:in `block in invoke'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/railties-7.2.1/lib/rails/command.rb:149:in `with_argv'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/railties-7.2.1/lib/rails/command.rb:69:in `invoke'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/railties-7.2.1/lib/rails/commands.rb:18:in `<main>'
    01:47:52 web.1  |       from /nix/store/2vg3asd3rmhng3wqvp781a1q5dhrr4yn-ruby-3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
    01:47:52 web.1  |       from /nix/store/2vg3asd3rmhng3wqvp781a1q5dhrr4yn-ruby-3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
    01:47:52 web.1  |       from /Hoom/WSL2/Projects/.devbox/virtenv/ruby/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
    01:47:52 web.1  |       from bin/rails:4:in `<main>'
    01:47:52 web.1  | exited with code 1
    01:47:52 system | sending SIGTERM to all processes
    01:47:52 js.1   | error: script "build" was terminated by signal SIGTERM (Polite quit request)
    01:47:52 js.1   | terminated by SIGTERM

I'm doing something wrong, can anyone help me deal with this?

camertron commented 8 hours ago

Hey @AlexeyMatskevich, sorry you're running into this! I just created a new Rails app following the steps you provided, and I am unable to reproduce the issue. I pushed up the app, can you take a look and see if this works on your machine? https://github.com/camertron/vc_test_app