stimulusreflex / futurism

Lazy-load Rails partials via CableReady
MIT License
407 stars 19 forks source link

Running installer on clean Rails 5.2 fails with TypeError: no implicit conversion of nil into String #133

Open evenreven opened 2 years ago

evenreven commented 2 years ago

Bug Report

I'm trying to add Futurism to a legacy Rails app running Rails 5.2, and I'm running into problems. Trying to recreate in a new 5.2 app has the same issues.

Describe the bug

Running bin/rails futurism:install --trace gives this error:

Trace ``` ** Invoke futurism:install (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute futurism:install yarn add v1.22.17 [1/4] Resolving packages... [2/4] Fetching packages... [3/4] Linking dependencies... [4/4] Building fresh packages... success Saved 1 new dependency. info Direct dependencies └─ @stimulus_reflex/futurism@1.2.0-pre9 info All dependencies └─ @stimulus_reflex/futurism@1.2.0-pre9 Done in 2.67s. Updating rails aborted! TypeError: no implicit conversion of nil into String /home/user/.rbenv/versions/2.6.9/lib/ruby/gems/2.6.0/gems/futurism-1.1.0/lib/tasks/futurism_tasks.rake:19:in `initialize' /home/user/.rbenv/versions/2.6.9/lib/ruby/gems/2.6.0/gems/futurism-1.1.0/lib/tasks/futurism_tasks.rake:19:in `open' /home/user/.rbenv/versions/2.6.9/lib/ruby/gems/2.6.0/gems/futurism-1.1.0/lib/tasks/futurism_tasks.rake:19:in `block (2 levels) in
' /home/user/.rbenv/versions/2.6.9/lib/ruby/gems/2.6.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute' /home/user/.rbenv/versions/2.6.9/lib/ruby/gems/2.6.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each' /home/user/.rbenv/versions/2.6.9/lib/ruby/gems/2.6.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute' /home/user/.rbenv/versions/2.6.9/lib/ruby/gems/2.6.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain' /home/user/.rbenv/versions/2.6.9/lib/ruby/2.6.0/monitor.rb:235:in `mon_synchronize' /home/user/.rbenv/versions/2.6.9/lib/ruby/gems/2.6.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain' /home/user/.rbenv/versions/2.6.9/lib/ruby/gems/2.6.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke' /home/user/.rbenv/versions/2.6.9/lib/ruby/gems/2.6.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task' /home/user/.rbenv/versions/2.6.9/lib/ruby/gems/2.6.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level' /home/user/.rbenv/versions/2.6.9/lib/ruby/gems/2.6.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each' /home/user/.rbenv/versions/2.6.9/lib/ruby/gems/2.6.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level' /home/user/.rbenv/versions/2.6.9/lib/ruby/gems/2.6.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads' /home/user/.rbenv/versions/2.6.9/lib/ruby/gems/2.6.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level' /home/user/.rbenv/versions/2.6.9/lib/ruby/gems/2.6.0/gems/railties-5.2.6.2/lib/rails/commands/rake/rake_command.rb:23:in `block in perform' /home/user/.rbenv/versions/2.6.9/lib/ruby/gems/2.6.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling' /home/user/.rbenv/versions/2.6.9/lib/ruby/gems/2.6.0/gems/railties-5.2.6.2/lib/rails/commands/rake/rake_command.rb:20:in `perform' /home/user/.rbenv/versions/2.6.9/lib/ruby/gems/2.6.0/gems/railties-5.2.6.2/lib/rails/command.rb:48:in `invoke' /home/user/.rbenv/versions/2.6.9/lib/ruby/gems/2.6.0/gems/railties-5.2.6.2/lib/rails/commands.rb:18:in `
' /home/user/.rbenv/versions/2.6.9/lib/ruby/gems/2.6.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require' /home/user/.rbenv/versions/2.6.9/lib/ruby/gems/2.6.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require' bin/rails:4:in `
' Tasks: TOP => futurism:install ```

To Reproduce

Create a new Rails 5.2 install with actioncable, then bundle add futurism and bin/rails futurism:install

Expected behavior

I expected it to install, or to give an error message with more information on what went wrong.

Screenshots or reproduction

[see above]

Versions

Futurism

External tools

Browser

[not applicable]

julianrubisch commented 2 years ago

Thanks for the report! Will try to get behind what's wrong

LinuxDevil commented 2 years ago

@julianrubisch Hey! Did you found out what happened? (Trying to solve it)

SpaYco commented 2 years ago

https://github.com/stimulusreflex/futurism/blob/master/lib/tasks/futurism_tasks.rake#L8-L13

This is not covering all of the possible locations the file could be, it either needs more paths or simply ask for user input if no file was found.

I fixed the issue by manually adding the file path (app/javascript/application.js).

I would still advise doing a manual installation because this auto-install is assuming some stuff, which might not be the case for everyone.

julianrubisch commented 2 years ago

In fairness, this was all written before importmaps-rails, jsbundling-Rails etc.

we‘re just in the process of streamlining all StimulusReflex and CableReady installers, futurism will come next 🤞

evenreven commented 2 years ago

Nice find @SpaYco, I was looking in the wrong place. I guess this is the root of my issue? Rails 5.2 didn't use Webpacker by default, so app/javascript doesn't exist unless you install it manually. And my legacy Rails app actually has been retrofitted to use vite_rails, which encourages using app/frontend/entrypoints. Any chance this gem's installer could be less opinionated about this, @julianrubisch? I'm not asking that you should cover every edge case, but maybe a prompt if the standard locations aren't found? Thanks!

julianrubisch commented 2 years ago

It definitely should and will. We’re just trying to reuse as much as possible between CR, SR, futurism and others

cc @marcoroth