Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] Element with ID #326

Open
richjdsmith opened this issue Jun 27, 2024 · 3 comments
Open

[question] Element with ID #326

richjdsmith opened this issue Jun 27, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@richjdsmith
Copy link

I am not sure where else to turn. I am getting this error code in VScode:

Element with id /home/richsmith/workspace/retiredmortgages/app/javascript/controllers/countchars_controller.js-countchars-true is already registered

I am at a loss as to what this means and what's causing it.

The controller itself is super simple:

import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
  static targets = ["name", "counter"]
  connect() {
    console.log("Countchars controller connected")
  }

  countCharacters(event) {
    let characters = this.nameTarget.value.length;
    this.counterTarget.innerText = characters;
  }
}

But no matter what I do, this error lives on. Any suggestions? place to turn?

@richjdsmith
Copy link
Author

It appears not to be related with any one controller. Possibly an importmaps issue?

@marcoroth
Copy link
Owner

Hey @richjdsmith, thanks for reporting this! Somehow I totally missed this, my bad!

I think it has to do with the parser and how it sees your application. Would you mind sharing your app/javascript/controllers/index.js and your app/javascript/controllers/application.js file? Thank you!

@marcoroth marcoroth added the bug Something isn't working label Jul 21, 2024
@luizkowalski
Copy link

luizkowalski commented Aug 31, 2024

hey, I'm seeing the same issue. Here is my application.js:

import { application } from './application'

import AutoremoveController from './autoremove_controller'

import AutosubmitController from './autosubmit_controller'

import DoubleConfirmController from './double_confirm_controller'

import DropdownController from './dropdown_controller'

import FormloaderController from './formloader_controller'

application.register('autoremove', AutoremoveController)
application.register('autosubmit', AutosubmitController)
application.register('double-confirm', DoubleConfirmController)
application.register('dropdown', DropdownController)
application.register('formloader', FormloaderController)

it is automatically formatted by Standard

a solution I found was to ignore index.js from Standard so that it doesn't mess with controllers:

"standard": {
    "ignore": [
      "app/javascript/controllers/index.js"
    ]
  }

and run bin/rails stimulus:manifest:update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants