Ever since AlpineJS upgraded to Alpine 3, I haven't been able to get it working with Rails 6 and webpacker, I've only been able to get it working when linking to the CDN version of Alpine.
In the past with AlpineJS 2 I've just had to run yarn add alpinejs then put require('alpinejs') in javascript/packs/application.js.
From everything I've read, it seems that when using Turbo on Rails 6.1 I need to do this:
// Alpine JS
import 'alpine-turbo-drive-adapter'
require('alpinejs')
(After installing the packages, obviously). I'm loading my javascript in my html header with <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>.
But, that still doesn't work. Does th AlpineJS NPM package just not work with webpacker and Rails?
How do I get this working instead of loading from the Alpine JS CDN?
UPDATE:
I made sure to run yarn add alpinejs and yarn add alpine-turbo-drive-adapter. I've also updated my packs/application.js file to make sure it is using Turbo and not Turbolinks. It looks like this now:
import Rails from "@rails/ujs"
import "@hotwired/turbo"
import * as ActiveStorage from "@rails/activestorage"
import "channels"
Rails.start()
ActiveStorage.start()
import "controllers"
// Custom JS files
import 'alpine-turbo-drive-adapter'
import Alpine from "alpinejs"
window.Alpine = Alpine
Alpine.start()
// require("./components/direct_uploads")
require("stylesheets/application.scss")
After those two updates, I'm now getting this console error:
TypeError: func(func, completeScope).catch is not a function. (In 'func(func, completeScope).catch(function (error2) {
return handleError(error2, el, expression);
})', 'func(func, completeScope).catch' is undefined)