stimulusreflex / stimulus_reflex

Build reactive applications with the Rails tooling you already know and love.
https://docs.stimulusreflex.com
MIT License
2.28k stars 172 forks source link

Installer fails on fresh Rails 5.2.3 app w/ webpacker 3.6 #81

Closed julianrubisch closed 4 years ago

julianrubisch commented 5 years ago

Bug Report

I have a legacy Rails app running on 5.2.3 that I wanted to try stimulus_reflex on, so I decided to first run a test on a fresh install, but the installer failed.

Describe the bug

The installer fails because no index.js file is present:

Errno::ENOENT: No such file or directory @ rb_sysopen - {...}/stimulus_reflex_test/app/javascript/controllers/index.js
bin/rails:4:in `<main>'

To Reproduce

mkdir stimulus_reflex_test
cd stimulus_reflex_test/
echo "source 'https://rubygems.org'" > Gemfile
echo "gem 'rails', '5.2.3'" >> Gemfile
bundle install
bundle exec rails new . --force --skip-bundle
echo "gem 'webpacker', '~> 3.5'" >> Gemfile
bundle update
bundle exec rails webpacker:install
bundle exec rails webpacker:install:stimulus
bundle add stimulus_reflex
bundle exec rails stimulus_reflex:install

Expected behavior

The installer should complete

Versions

Output of bin/rails webpacker:info:

Ruby: ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18] Rails: 5.2.3 Webpacker: 3.6.0 Node: v10.15.3 Yarn: 1.19.1

@rails/webpacker: stimulus_reflex_test@ {...}/stimulus_reflex_test └── @rails/webpacker@3.5.5

Is bin/webpack present?: true Is bin/webpack-dev-server present?: true Is bin/yarn present?: true

leastbad commented 5 years ago

I'm really sorry to hear that you're having issues. Stick with us and we'll stick with you.

First thing, here is an index.js for you to install into app/javascript/controllers/index.js:

import { Application } from 'stimulus'
import { definitionsFromContext } from 'stimulus/webpack-helpers'
import StimulusReflex from 'stimulus_reflex'

const application = Application.start()
const context = require.context('controllers', true, /_controller\.js$/)
application.load(definitionsFromContext(context))
StimulusReflex.initialize(application)

Next, can you tell me where you got the specific installation instructions that you're following?

julianrubisch commented 5 years ago

Thanks for the quick reply.

I can paste in the index.js for sure :-) Imho the question is whether stimulus_reflex and the installer should support older versions?

I followed these instructions because I couldn’t find other ones: https://stackoverflow.com/a/52979051/4341756

julianrubisch commented 5 years ago

To be clear: my problem is NOT getting the test app to run. My problem is getting the other (and possibly some more) apps to run that were generated before there was an index.js file, i.e. created with webpacker < 4

julianrubisch commented 5 years ago

I suppose that issue could be solved by instead amending the application.js file...

leastbad commented 5 years ago

Hey Julian, I just wanted to say that I'm following along. I was able to sneak in my message last night as I was preparing for bed, but seeing as you weren't having a small issue I decided to wait to see what @hopsoft would suggest. Unfortunately, I have zero experience running StimulusReflex with Rails 5 and I was not involved in the creation of the installer.

Either way, we should make sure that the installer works on 5.x or update the documentation to suggest workarounds.

julianrubisch commented 5 years ago

No need to apologize in any way. I prepared a small PR #82 in the meantime. (and created that other issue ;-) )