I am currently facing an issue when I try to configure the actiontext editor in rails 7.1.3 to handle YouTube videos embedded.
Currently running rails 7.1.3, ruby 3.2.0, and using importmaps.
(Following Chris Oliver's excellent example https://www.youtube.com/watch?v=2iGBuLQ3S0c There is a written guide here - https://dev.to/superails/ruby-on-rails-embed-youtube-videos-with-actiontext-tldr-3m35)
I am getting this error - Uncaught SyntaxError: The requested module 'trix' does not provide an export named 'default' (at youtube.js:1:8) The error is understandable, but I don't know how to fix it.
In my youtube.js file I import trix like this.
import Trix from "trix"
import Rails from "@rails/ujs"
let lang = Trix.config.lang;
Trix.config.toolbar = {
getDefaultHTML: function() {
return `
<div class="trix-button-row">
.....
I tried without luck to change it to
import * as Trix from "trix"
When I look into the trix.js, I do see an export:
export{Wn as default};
My importmap.rb looks like this:
Pin npm packages by running ./bin/importmap
pin "application"
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
pin "@hotwired/stimulus", to: "stimulus.min.js"
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
pin_all_from "app/javascript/controllers", under: "controllers"
pin "@rails/actiontext", to: "actiontext.esm.js"
pin "@rails/ujs", to: "@rails--ujs.js" # @7.1.3
pin "trix" # @2.0.10
Has anyone experienced this issue before? And maybe found a solution?
pin "trix"links to a UMD build which doesn't have any exports, it only exposes Trix globally. That meansimport "trix"is all you need. This build is meant to work with plain sprockets as well:https://github.com/rails/rails/blob/main/actiontext/app/assets/javascripts/trix.js
On the other hand, ESM build has a default export:
https://cdn.jsdelivr.net/npm/[email protected]/dist/trix.esm.js
If you've pinned
trixseparately into your vendor directory (which would be esm build), it won't change anything because vendor is all the way at the end of the assets paths:This is the best I could figure out to fix the order:
Changing your pin to jspm url also can fix this, however url pins are no longer a thing by default in
importmap-rails v2, so this is a manual copy-paste operation: