railsadminteam / rails_admin

RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data
MIT License
7.88k stars 2.25k forks source link

Running rails_admin:install raises "@popperjs/core" importmap error #3694

Closed punkstar closed 1 week ago

punkstar commented 4 weeks ago

Describe the bug Unable to run rails g rails_admin:install on a fresh Rails project.

Reproduction steps

$ rails new railsadmintest
$ bundle add rails_admin --version="~>3.0"
$ bundle install
$ bundle exec rails g rails_admin:install

...truncated...

/Users/nrj/.rvm/gems/ruby-3.3.0/gems/rails_admin-3.2.0.beta/lib/generators/rails_admin/importmap_formatter.rb:17:in `format': undefined method `[]' for nil (NoMethodError)

      imports['@popperjs/core'].gsub!('lib/index.js', 'dist/esm/popper.js')
             ^^^^^^^^^^^^^^^^^^
Full output from g rails_admin:install ``` ? Where do you want to mount rails_admin? Press for [admin] > route mount RailsAdmin::Engine => '/admin', as: 'rails_admin' create config/initializers/rails_admin.rb - Using [importmap] for asset delivery method run yarn add rails_admin@3.2.0-beta from "." create app/javascript/rails_admin.js /Users/nrj/.rvm/gems/ruby-3.3.0/gems/rails_admin-3.2.0.beta/lib/generators/rails_admin/importmap_formatter.rb:17:in `format': undefined method `[]' for nil (NoMethodError) imports['@popperjs/core'].gsub!('lib/index.js', 'dist/esm/popper.js') ^^^^^^^^^^^^^^^^^^ from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/rails_admin-3.2.0.beta/lib/generators/rails_admin/install_generator.rb:100:in `configure_for_importmap' from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/rails_admin-3.2.0.beta/lib/generators/rails_admin/install_generator.rb:33:in `install' from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/thor-1.3.1/lib/thor/command.rb:28:in `run' from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/thor-1.3.1/lib/thor/invocation.rb:127:in `invoke_command' from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/thor-1.3.1/lib/thor/invocation.rb:134:in `block in invoke_all' from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/thor-1.3.1/lib/thor/invocation.rb:134:in `each' from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/thor-1.3.1/lib/thor/invocation.rb:134:in `map' from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/thor-1.3.1/lib/thor/invocation.rb:134:in `invoke_all' from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/thor-1.3.1/lib/thor/group.rb:232:in `dispatch' from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/thor-1.3.1/lib/thor/base.rb:584:in `start' from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/railties-7.2.0/lib/rails/generators.rb:261:in `invoke' from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/railties-7.2.0/lib/rails/commands/generate/generate_command.rb:26:in `perform' from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/thor-1.3.1/lib/thor/command.rb:28:in `run' from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/thor-1.3.1/lib/thor/invocation.rb:127:in `invoke_command' from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/railties-7.2.0/lib/rails/command/base.rb:178:in `invoke_command' from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/thor-1.3.1/lib/thor.rb:527:in `dispatch' from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/railties-7.2.0/lib/rails/command/base.rb:73:in `perform' from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/railties-7.2.0/lib/rails/command.rb:71:in `block in invoke' from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/railties-7.2.0/lib/rails/command.rb:149:in `with_argv' from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/railties-7.2.0/lib/rails/command.rb:69:in `invoke' from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/railties-7.2.0/lib/rails/commands.rb:18:in `
' from /Users/nrj/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `require' from /Users/nrj/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require' from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require' from bin/rails:4:in `
' ```

Expected behavior Expect rails r rails_admin:install to succeed.

Additional context

/Users/nrj/.rvm/gems/ruby-3.3.0/gems/rails_admin-3.2.0.beta/lib/generators/rails_admin/importmap_formatter.rb:17:in `format': undefined method `[]' for nil (NoMethodError)

      imports['@popperjs/core'].gsub!('lib/index.js', 'dist/esm/popper.js')
             ^^^^^^^^^^^^^^^^^^
    from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/rails_admin-3.2.0.beta/lib/generators/rails_admin/install_generator.rb:100:in `configure_for_importmap'
    from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/rails_admin-3.2.0.beta/lib/generators/rails_admin/install_generator.rb:33:in `install'
    from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/thor-1.3.1/lib/thor/command.rb:28:in `run'
    from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/thor-1.3.1/lib/thor/invocation.rb:127:in `invoke_command'
    from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/thor-1.3.1/lib/thor/invocation.rb:134:in `block in invoke_all'
    from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/thor-1.3.1/lib/thor/invocation.rb:134:in `each'
    from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/thor-1.3.1/lib/thor/invocation.rb:134:in `map'
    from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/thor-1.3.1/lib/thor/invocation.rb:134:in `invoke_all'
    from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/thor-1.3.1/lib/thor/group.rb:232:in `dispatch'
    from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/thor-1.3.1/lib/thor/base.rb:584:in `start'
    from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/railties-7.2.0/lib/rails/generators.rb:261:in `invoke'
    from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/railties-7.2.0/lib/rails/commands/generate/generate_command.rb:26:in `perform'
    from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/thor-1.3.1/lib/thor/command.rb:28:in `run'
    from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/thor-1.3.1/lib/thor/invocation.rb:127:in `invoke_command'
    from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/railties-7.2.0/lib/rails/command/base.rb:178:in `invoke_command'
    from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/thor-1.3.1/lib/thor.rb:527:in `dispatch'
    from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/railties-7.2.0/lib/rails/command/base.rb:73:in `perform'
    from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/railties-7.2.0/lib/rails/command.rb:71:in `block in invoke'
    from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/railties-7.2.0/lib/rails/command.rb:149:in `with_argv'
    from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/railties-7.2.0/lib/rails/command.rb:69:in `invoke'
    from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/railties-7.2.0/lib/rails/commands.rb:18:in `<main>'
    from /Users/nrj/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
    from /Users/nrj/.rvm/rubies/ruby-3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
    from /Users/nrj/.rvm/gems/ruby-3.3.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
    from bin/rails:4:in `<main>'
HolyWalley commented 4 weeks ago

same happens on Rails 7.1.3.4 and rails admin 3.1.4, ruby 3.3.0

original issue https://github.com/railsadminteam/rails_admin/issues/3609

P.S. I've tried with 3.1.2 but got the same error

bkwaku commented 4 weeks ago

Check this out - https://github.com/railsadminteam/rails_admin/issues/3683

punkstar commented 3 weeks ago

I'm not familiar with jspm / importmaps, etc, so take this with a pinch of salt. This issue looks like this is related to the fact that we reference a package in the codebase that's no longer present in jQuery UI.

When running the import map generator for rails_admin@3.2.0-beta (in fact, going back to >3.0) I get the error:

Error: No './ui/ie.js' exports subpath defined in https://ga.jspm.io/npm:jquery-ui@1.14.0/ resolving jquery-ui/ui/ie.js imported from https://ga.jspm.io/npm:rails_admin@3.1.0-beta/src/rails_admin/base.js.

We can see the file referenced:

https://github.com/railsadminteam/rails_admin/blob/53b89c9161e48c0f9b4ecd5f544398c9360ea50f/src/rails_admin/base.js#L13

However, this file was removed from jquery-ui in 1.14.0.

The package.json used to build 3.2.0-beta constrains jquery-ui to ^1.12.1.

As I'm writing this, I noticed a constraint change committed as part of https://github.com/railsadminteam/rails_admin/commit/5245d5bb91691d646219b5243f3f881a0144a3fd which looks promising from @mshibuya 🥳

punkstar commented 3 weeks ago

Related to https://github.com/railsadminteam/rails_admin/issues/3695, https://github.com/railsadminteam/rails_admin/issues/3692.

jacob-carlborg-apoex commented 3 weeks ago

I'm running into this issue as well. It tried using the master branch, did not help. Does the NPM package need to be updated as well?

punkstar commented 3 weeks ago

I'm running into this issue as well. It tried using the master branch, did not help. Does the NPM package need to be updated as well?

I believe so, RailsAdmin::Version.js will return 3.2.0-beta.

https://github.com/railsadminteam/rails_admin/blob/53b89c9161e48c0f9b4ecd5f544398c9360ea50f/lib/rails_admin/version.rb#L16-L18

https://github.com/railsadminteam/rails_admin/blob/53b89c9161e48c0f9b4ecd5f544398c9360ea50f/package.json#L3

mshibuya commented 1 week ago

This was fixed as 3.2.0.rc was released. Please use it.