Giter Site home page Giter Site logo

Comments (9)

kuei0221 avatar kuei0221 commented on July 28, 2024 1

Cool, that is what exactly we need. I found this file here https://github.com/rails/webpacker/blob/v4.0.0/lib/install/examples/stimulus/controllers/index.js,
we can just place it in the controller directory and stimulus:install:webpacker will handle it for us.
I will make a PR for this 😄

from stimulus-rails.

jacobdaddario avatar jacobdaddario commented on July 28, 2024

Is there a controllers directory anywhere in your application? It may be that Stimulus was installed into the asset pipeline, meaning that the controllers folder is in yours app/assets folder. I believe that the error is saying that Webpack can't find the controllers folder in its load path.

from stimulus-rails.

guizero avatar guizero commented on July 28, 2024

Hey @jacobdaddario . Yes, the javascripts/controllers is there with the hello_world_controller.js

I believe that the imported controllers was coming from this gem. Do I have to create a controllers/index.js manually?

from stimulus-rails.

guizero avatar guizero commented on July 28, 2024

Just so you understand the steps I have followed.

Using Rails 6.1.1.1

rails new app
cd app
bundle install
bundle add hotwire-rails
rails hotwire:install

I am using rails with webpacker as default.

And then scaffolded a posts model. Just that.

When visiting localhost:3000/posts the error shows up

from stimulus-rails.

kuei0221 avatar kuei0221 commented on July 28, 2024

I have encountered the same problem and find the solution in hotwire's document
The path has modified to fit the directory hotwire auto-created.

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))

from stimulus-rails.

guizero avatar guizero commented on July 28, 2024

Hey @kuei0221 , cool! I'd done the same to make it work. I just believe that this should be added to this gem, I mean, when using webpacker (currently default on rails apps) this index should be created as well.

Actually, when you run
rails webpacker:install:stimulus

The file is created.

from stimulus-rails.

guizero avatar guizero commented on July 28, 2024

I am happy to see that it was already merged =) @kuei0221

from stimulus-rails.

afomera avatar afomera commented on July 28, 2024

Ran into this issue when I added hotwire-rails and then ran the install script, Appears fixed in main from when using stimulus-rails from GitHub. Hoping @dhh or friends can ship a new release soon so we don't need to use the gem from GitHub (and so hotwire-rails's gem will just work) 🤞

from stimulus-rails.

noctivityinc avatar noctivityinc commented on July 28, 2024

The README needs to be updated to reflect the new steps

from stimulus-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.