Class constructor Controller cannot be invoked without 'new' (3.0.0-beta1)
See original GitHub issueJust had a go at updating our Stimulus 2.x app to the beta. We’re using Rails/Webpacker.
I think there’s some missing parts of the docs around this change (in the push to importmaps) so I did have to guess some of the new Webpack configuration code. Namely - definitionsFromContext
used to come from stimulus/webpack-helpers
and I think it now comes from just @hotwired/stimulus
.
import { Application } from "@hotwired/stimulus";
import { definitionsFromContext } from "@hotwired/stimulus";
const application = Application.start();
const context = require.context("./controllers", true, /\.js$/);
application.load(definitionsFromContext(context));
This runs, however in the browser I get the following error - following the stacktrace it occurs in each of my controller modules.
Uncaught (in promise) TypeError: Class constructor Controller cannot be invoked without 'new'
at new _default (application.js:3048)
at new extended (vendors-node_modules_babel_runtime_regenerator_index_js-node_modules_hotwired_stimulus_dist_s-68817b.js:1338)
at new Context (vendors-node_modules_babel_runtime_regenerator_index_js-node_modules_hotwired_stimulus_dist_s-68817b.js:1198)
at Module.fetchContextForScope (vendors-node_modules_babel_runtime_regenerator_index_js-node_modules_hotwired_stimulus_dist_s-68817b.js:1400)
at Module.connectContextForScope (vendors-node_modules_babel_runtime_regenerator_index_js-node_modules_hotwired_stimulus_dist_s-68817b.js:1386)
at Router.scopeConnected (vendors-node_modules_babel_runtime_regenerator_index_js-node_modules_hotwired_stimulus_dist_s-68817b.js:1705)
at ScopeObserver.elementMatchedValue (vendors-node_modules_babel_runtime_regenerator_index_js-node_modules_hotwired_stimulus_dist_s-68817b.js:1623)
at ValueListObserver.tokenMatched (vendors-node_modules_babel_runtime_regenerator_index_js-node_modules_hotwired_stimulus_dist_s-68817b.js:814)
at TokenListObserver.tokenMatched (vendors-node_modules_babel_runtime_regenerator_index_js-node_modules_hotwired_stimulus_dist_s-68817b.js:747)
at vendors-node_modules_babel_runtime_regenerator_index_js-node_modules_hotwired_stimulus_dist_s-68817b.js:741
Nothing fancy going on with my controllers - just updated the import from stimulus
to @hotwired/stimulus
as expected.
import { Controller } from "@hotwired/stimulus";
export default class extends Controller {
//
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:16 (6 by maintainers)
Top Results From Across the Web
Class constructor Controller cannot be invoked without 'new ...
I migrated from "stimulus": "^2.0.0" to "@hotwired/stimulus": "^3.0.0" I got an error Uncaught TypeError: Class constructor Controller ...
Read more >Upgraded to Stimulus 3, console error Cannot call a class ...
Now, all my controllers generates the console error Unhandled Promise Rejection: TypeError: Cannot call a class constructor without |new| .
Read more >Class constructor Class cannot be invoked without 'new'
I'm getting the following error in the console of the browser, when trying to access my route “login”: Uncaught (in promise) TypeError: ...
Read more >Javascript ES6 TypeError Class constructor Client cannot be ...
When I try to execute nodemon command I always see this error TypeError: Class constructor Client cannot be invoked without 'new'.
Read more >stimulusjs - Bountysource
Having two NOT NESTED elements using the same controller, like here: ... Class constructor Controller cannot be invoked without 'new' (3.0.0-beta1) $ 0....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In
package.json
add"not IE 11"
to"browserslist"
@m3xq’s suggestion appears to have done the trick for me.