This is probably not so much an issue but to help others that might be installing Stimulus in Ruby on Rails and following some of the online tutorials.
I get an error TypeError: Object(...) is not a function on the line in my application.js for autoload(controllers, application)
I notice in the installation guides that we should now be doing the following.
import { Application } from "stimulus"
import { definitionsFromContext } from "stimulus/webpack-helpers"
const application = Application.start()
const context = require.context("./controllers", true, /\.js$/)
application.load(definitionsFromContext(context))
But in many tutorials and in some other comments on issues this code I have tried is being used.
Also out of curiousity, I tried changing to:
import { Application } from "stimulus"
import { autoload } from "stimulus/webpack-helpers"
const application = Application.start()
const controllers = require.context("./controllers", true, /\.js$/)
application.load(autoload(controllers))
But it also threw the same error. Is the variable name controllers reserved?
The webpack helper was named autoload in version 0.9. We changed the API in version 1.0, removing autoload and replacing it with definitionsFromContext.
Most helpful comment
The webpack helper was named
autoloadin version 0.9. We changed the API in version 1.0, removingautoloadand replacing it withdefinitionsFromContext.