I’m trying to use Stimulus in a non-Rails application and I’ve installed Stimulus using NPM and integrated it with Webpack as shown in the Stimulus handbook. I’m also using Yarn to build it all together.
Anyway, I have a very simple Stimulus controller - game_controller.js
import { Controller } from "stimulus"
export default class extends Controller {
static targets = [ "game" ]
}
And this fails to build with the following error:
WARNING in ./Resources/Javascripts/controllers/game_controller.js 4:17
Module parse failed: Unexpected token (4:17)
You may need an appropriate loader to handle this file type.
|
| export default class extends Controller {
> static targets = [ "source" ]
| }
|
@ ./Resources/Javascripts/controllers sync \.js$ ./bracket_controller.js
@ ./Resources/Javascripts/application.js
✨ Done in 1.65s.
Removing the static targets = ["source"]
line fixes the build issue. Any ideas on what is going on or if I’m missing something?
Here is my application.js
for reference as well.
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))