Stimulus: TypeError: Object(...) is not a function on application.js line 'autoload(controllers, application)'

Created on 20 Mar 2018  路  1Comment  路  Source: hotwired/stimulus

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?

Most helpful comment

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.

>All comments

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.

Was this page helpful?
0 / 5 - 0 ratings