Adding HighLightJS to rails 7.1 with ImportMaps

I'm trying to add HightlightJS

# importmap.rb    
pin "highlightjs", to: ""

// application.js
import hljs from "highlightjs"

Which gives error:

Uncaught SyntaxError: ambiguous indirect export: default

I'm trying to use the simple quickstart here:

What am I doing wrong? Importmaps? Or HighlightJS? How do I get it working?

The root of the problem was I was doing this:

bin/importmap pin highlightjs                                                                                                                                                         ✹
Pinning "highlightjs" to[email protected]/highlight.pack.js

and then breaking it worse by editing the importmap entry to the up to date but not ES module version.

As per @alex answer, it needs to be this:

bin/importmap pin highlight.js                                                                                                                                                        ✹
Pinning "highlight.js" to[email protected]/es/index.js


  • You have to use ES module package:

    pin "highlight.js", to: ""
    import hljs from "highlight.js"

    Or just use importmap command:

    bin/importmap pin highlight.js
    import hljs from "highlight.js"