adrienpoly/rails_stimulus_flatpickr

Trying this out with Rails 7, Hotwire and Stimulus, busted

resistorsoftware opened this issue · 2 comments

I am trying a basic example of stimulus-flatpickr

But when I try my esbuild of the packages and try and run the sample code, it stops at this:

node_modules/stimulus-flatpickr/dist/index.m.js:1:27:
13:59:49 js.1 | 1 │ import { Controller } from 'stimulus';

Any idea how to fix that?

I'm not able to compile webpacker for a Rails 6 app with @hotwired/stimulus, either. It fails with error:

Module not found: Error: Can't resolve 'stimulus' in '/home/ubuntu/environment/giggo/node_modules/stimulus-flatpickr/dist'

Does stimulus-flatpickr support the new @hotwired/stimulus package at all?

The solution for me was simple. Just change the import. It is NOT import { Controller } from 'stimulus'; but instead:

import Flatpickr from "stimulus-flatpickr";

And then extend from Flatpickr and not Controller

export default class extends Flatpickr {

And with that, it all works perfect for me, Rails 7, Hotwire and Flatpikr