Comments (9)
as this point, the only way I can get stimulus working on new Rails 7 apps is to use neither --css=bootstrap
nor --javascript=webpack
when I use either of these, I get some kind of a "registry" file at app/javascript/controllers/applicationl.js (see below)
please note that this file is inconsistent with what is generated by the default rails new, which uses a dynamic loader that makes the registering of each Stimulus class name (and thus rebuilding of this file) unnecessary.
However, when I copy the dynamic loader content into an app generated in this registry-style pattern, it doesn't seem to work. (That is, I can't seem to swap out the dynamic loader content for the registry content.)
TO be clear, under these circumstances, I can't get get any Stimulus controllers to load at all, with or without the dynamic loader. It is only with the default rails new that I can get the stimulus controllers to load.
here is the registry loader that comes with --css=bootstrap
or --javascript=webpack
// This file is auto-generated by ./bin/rails stimulus:manifest:update
// Run that command whenever you add a new controller or create them with
// ./bin/rails generate stimulus controllerName
import { application } from "./application"
import HelloController from "./hello_controller"
application.register("hello", HelloController)
from jsbundling-rails.
I can't replicate this on Rails 7.0.1. When you start with --javascript=webpack you get the static index loader by design. The dynamic loader is only intended to be used with import maps.
Steps to get things working:
- rails new testapp --javascript=webpack
- rails generate scaffold post title:string
- Add
<div data-controller="hello"></div>
to app/views/posts/index.html.erb - See "Hello World" from Stimulus on localhost:3000/posts
from jsbundling-rails.
hmm... this is most odd. I am doing these exact steps but I am not getting this. I am still seeing my own original error (no stimulus controllers connected). I am using the latest version of Chrome and have been over it several times...
let me re-create here:
rails new testapp --javascript=webpack
Rails new initial commit:
https://github.com/jasonfb/js-bundling-issue74/commit/fcf75494d4152ad0ebb44ee3f69537465b2c2219
rails generate scaffold post title:string
this generates:
https://github.com/jasonfb/js-bundling-issue74/commit/de9d15df449732a6052ccb260142b7b169f87b8e
Add
to app/views/posts/index.html.erbhttps://github.com/jasonfb/js-bundling-issue74/commit/92144f0c26a6ce8efe3bd0b48d238b8d24270759
Then I migrate the database rails db:migrate
But still the Stiummy controller won't connect at all. --- no "Hello world" or nothing
I added a console output too:
https://github.com/jasonfb/js-bundling-issue74/
@dhh -- this is very odd, it must be something else that we haven't thought of. is it possible you have cached gem dependencies on your machine that have been yanked from Rubygems?
Could please do either of the following:
-
ask someone else to replicate the same steps as above to see what they get
-
pull my repo above (https://github.com/jasonfb/js-bundling-issue74/) and let me know when you pull my repo if you see the Stimulus controller connect
-
Re-create the steps on your machine, commit & and then push the example code so that I might pull it and see if it works on my machine.
In the event that you or I have cached yanked gems, we could be building Rails against different default causing this issue. we would then be able to compare the Gemfile.lock
I'm certain there is a very reasonable explanation (but of course, I feel like a crazy person because it seems like it should be obvious).
the only explanation I can think of is this is similar to the yanked turbo-rails versions at the 7.x version range which were causing those versions to be installed above the lower-numbered ones..
I suppose I could implode my ruby and re-install all the gems but still if I had your lockfile that would be helpful as I could compare gem by gem to see what the difference is.
from jsbundling-rails.
I tested this against Ruby 2.7. I will check it against Ruby 3.0 now and report back here.
here's it recreated against Ruby 3.1.0:
https://github.com/jasonfb/-js-bundling-issue74-ruby310
I've recreated it multiple times and there is no inconsistency-- any new app created with these steps do not have Stimulus enabled and I can't even figure out why not. (They also do not have Turbo enabled for me).
Only apps that I create without --css
or --javascript
can I get Turbo or Stimulus working. As well, I didn't have Ruby 3.1 before this so it must have installed all the gems fresh.
I suspect the only explanation for this that I can surmise is that DHH has some yanked cached gems on his machine causing his apps to come out in an OK state.
Can someone else please test and push your result publicly so that we might compare the Gemfile.lock versions? Thank you.
from jsbundling-rails.
ok @dhh -- I have now recreated this issue using a 2nd laptop that did not previously have Rails 7.0.1 on it. same result. Would you please consider that your machine may have yanked cached gems causing your new rails build to work for only you but not for everyone else?
Please re-open the issue or supply the rails build for us to examine the Gemfile.lock
. this does not make sense.
from jsbundling-rails.
here is the Gemfile.lock that I am getting. I can't see anything wrong with it by examination, but if possibly your machine has yanked cached gems you will be building against gems that make your apps work.
https://gist.github.com/jasonfb/fa99be3bed6eec5a394b0205a53c9f56
from jsbundling-rails.
@dhh -- nevermind!
the problem here is that this is what happens when you don't actually install webpack as a node module using npx webpack
from jsbundling-rails.
RESOLITION & NOTICE:
The problem here is that I was running my Rails server with rails s
, which won't install webpack as a node module.
You are now encouraged to use the new development command, which takes care of both (although requires a reload of the web browser to kick in webpack:
bin/dev rails
If using rails server (rails s
), you must run npx webpack
first or else your webpack won't be installed.
Remember, this affects only apps built using the new --css
and --javascript
flags.
there are likely no yanked cached gems on DHH's machine I just didn't know what else to think of next!
from jsbundling-rails.
from jsbundling-rails.
Related Issues (20)
- Minor doc update per console warning HOT 1
- Large size of application.js produced by esbuild HOT 1
- Daily alerts not being delivered HOT 1
- bin/dev: 8: exec: foreman: not found HOT 3
- Could not resolve "@hotwired/turbo-rails" HOT 4
- yarn: not found while deployment by mina HOT 1
- jsbundling-rails: Command build failed, ensure yarn is installed and `yarn build` runs without errors HOT 4
- Question: could we also use jsbundling with npm instead of yarn? HOT 2
- How to confirm that yarn dependencies are installed? HOT 1
- Changing from outputting as application.js to something else
- Assets:precomipile task has to be run twice HOT 8
- Refer asset path inside of javascript file HOT 1
- JS is compiling/Shows in script tag but doesn't execute HOT 1
- Webpacker migration asset_pack_path in jsbundling-rails
- bin/dev crashes on new app HOT 3
- ActionView::Template::Error (The asset "application.js" is not present in the asset pipeline): HOT 3
- jsbundling 1.2 doesn't compile javascript HOT 2
- bun install fails without .gitattributes file in project root HOT 3
- Allow npm or pnpm to be used as a package manager instead of yarn HOT 5
- bun individual files HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsbundling-rails.