Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do I find out why Stimulus controllers aren't getting compiled? Asset Pipeline problem

Greg S asked in Javascript

I updated a Rails 6 app to Rails 7 and changed from Webpacker to esbuild/webpack. Added Stimulus, and after not getting controllers to work tried a basic hello_controller and then searched the application.js as seen in Chrome and no 'hello' or "Hello" I made a basic app to compare. I've toggled many settings and don't know where to look.

webpack.config.js are identical. hello_controller.js is identical.

Beginning of Gemfile:

ruby '3.0.2'
gem "rails", "~> 7.0.4"
gem "sprockets-rails"
gem 'sassc-rails', '>= 2.0.1'
gem 'jsbundling-rails'
gem "cssbundling-rails", "~> 1.1"
gem 'turbo-rails'
gem 'stimulus-rails'
gem 'puma', "~> 5.0"
gem 'pg'

package.json

{
  "license": "ISC",
  "main": "application.js",
  "dependencies": {
    "@fortawesome/fontawesome-free": "^5.12.1",
    "@hotwired/stimulus": "^3.1.1",
    "@hotwired/turbo-rails": "^7.0.0-rc.1",
    "@popperjs/core": "^2.11.6",
    "@rails/actiontext": "^6.0.0",
    "@rails/ujs": "^6.0.1",
    "bootstrap": "^5.2.2",
    "bootstrap-icons": "^1.10.2",
    "exiftool": "^0.0.3",
    "imports-loader": "^0.8.0",
    "jquery": "^3.4.1",
    "jqueryui": "^1.11.1",
    "leaflet": "^1.7.1",
    "leaflet.timeline": "1.3.0",
    "lodash": "^4.17.15",
    "mapbox": "^1.0.0-beta10",
    "ol": "^7.1.0",
    "ol-ext": "^4.0.4",
    "ol-layerswitcher": "^4.1.0",
    "ol-loupe": "^1.0.1",
    "ol-popup": "^5.0.0",
    "rails-erb-loader": "^5.5.2",
    "sass": "^1.56.1",
    "stimulus": "^3.1.1",
    "trix": "^1.0.0",
    "webpack": "^5.75.0"
  },
  "devDependencies": {
    "@prettier/plugin-ruby": "^0.22.0",
    "prettier": "^2.2.1",
    "webpack-cli": "^5.0.0"
  },
  "scripts": {
    "build": "webpack --config ./webpack.config.js",
    "build:css": "sass ./app/assets/stylesheets/application.bootstrap.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules"
  }
}

command line server launch without timestamp

➜ bd
web.1  | started with pid 35879
js.1   | started with pid 35880
css.1  | started with pid 35881
js.1   | yarn run v1.22.19
css.1  | yarn run v1.22.19
js.1   | $ webpack --config ./webpack.config.js --watch
css.1  | $ sass ./app/assets/stylesheets/application.bootstrap.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules --watch
css.1  | Sass is watching for changes. Press Ctrl-C to stop.
css.1  |
web.1  | => Booting Puma
web.1  | => Rails 7.0.4 application starting in development
web.1  | => Run `bin/rails server --help` for more startup options
web.1  | Puma starting in single mode...
web.1  | * Puma version: 5.6.5 (ruby 3.0.2-p107) ("Birdie's Version")
web.1  | *  Min threads: 5
web.1  | *  Max threads: 5
web.1  | *  Environment: development
web.1  | *          PID: 35879
web.1  | * Listening on http://127.0.0.1:3000
web.1  | * Listening on http://[::1]:3000
web.1  | Use Ctrl-C to stop
js.1   | asset application.js 503 KiB [compared for emit] [minimized] [big] (name: application) 1 related asset
js.1   | orphan modules 2.58 MiB [orphan] 342 modules
js.1   | runtime modules 997 bytes 4 modules
js.1   | cacheable modules 1.75 MiB
js.1   |   modules by path ./node_modules/ol/ 109 KiB
js.1   |     modules by path ./node_modules/ol/*.js 74.9 KiB 18 modules
js.1   |     modules by path ./node_modules/ol/layer/*.js 22.2 KiB 3 modules
js.1   |     modules by path ./node_modules/ol/events/*.js 7.39 KiB
js.1   |       ./node_modules/ol/events/Event.js 1.46 KiB [built] [code generated]
js.1   |       + 2 modules
js.1   |     ./node_modules/ol/control/Control.js 4.44 KiB [built] [code generated]
js.1   |     ./node_modules/ol/extent/Relationship.js 200 bytes [built] [code generated]
js.1   |   ./app/javascript/application.js + 224 modules 1.59 MiB [built] [code generated]
js.1   |   ./node_modules/ol-layerswitcher/dist/ol-layerswitcher.js 23.5 KiB [built] [code generated]
js.1   |   ./node_modules/@rails/actioncable/src/index.js + 9 modules 19.1 KiB [built] [code generated]
js.1   |   ./node_modules/rbush/rbush.min.js 6.31 KiB [built] [code generated]
js.1   |
js.1   | WARNING in configuration
js.1   | The value 'hashed' for option 'optimization.moduleIds' is deprecated. Use 'deterministic' instead.
js.1   |
js.1   | WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).
js.1   | This can impact web performance.
js.1   | Assets:
js.1   |   application.js (503 KiB)
js.1   |
js.1   | WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance.
js.1   | Entrypoints:
js.1   |   application (503 KiB)
js.1   |       application.js
js.1   |
js.1   | WARNING in webpack performance recommendations:
js.1   | You can limit the size of your bundles by using import() or require.ensure to lazy load some parts of your application.
js.1   | For more info visit https://webpack.js.org/guides/code-splitting/
js.1   |
js.1   | webpack 5.75.0 compiled with 4 warnings in 2885 ms
web.1  | Started GET "/" for ::1 at 2022-11-26 17:43:46 -0800
web.1  |   ActiveRecord::SchemaMigration Pluck (1.1ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
web.1  | Processing by StaticPagesController#home as HTML
web.1  |   Rendering layout layouts/application.html.erb
web.1  |   Rendering static_pages/home.html.erb within layouts/application
web.1  |   Rendered static_pages/home.html.erb within layouts/application (Duration: 1.1ms | Allocations: 1462)
web.1  |   Rendered layouts/_header.html.erb (Duration: 2.7ms | Allocations: 4997)
web.1  |   Rendered layouts/_footer.html.erb (Duration: 0.6ms | Allocations: 556)
web.1  |   Rendered layout layouts/application.html.erb (Duration: 7.0ms | Allocations: 9376)
web.1  | Completed 200 OK in 10ms (Views: 8.2ms | ActiveRecord: 0.0ms | Allocations: 13007)
web.1  |
web.1  |

No console errors

Reply

Not an answer, but I got it working by running rails assets:precompile. Shouldn't this be part of Profile.dev? or something like that?

Still curious about original question of how to see what is happening and what should happen.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 81,842+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2024 GoRails, LLC. All rights reserved.