I’m on edge rails using importmap and my stimulus controller is taking a long time to connect (more than 5 seconds). I’m gettting the following in my console, but from what I found it’s probably not the cause of the slowdown:
Uncaught TypeError: Error resolving module specifier “application”. Relative module specifiers must start with “./”, “../” or “/”.
^^ Module TypeError above is polyfilled and can be ignored ^^
Someone has any idea, I would love to see my pages reload quicker ?
I have experience with several applications using importmap with stimulus controllers and load times are milliseconds, not seconds. Can you provide a github or online example demonstrating the delay?
Thanks for the response! While I was preparing the example I found the problem. My controller is importing highlight.js and this is causing tons of requests:
import hljs from "highlight.js/lib/core"
import ruby from 'highlight.js/lib/languages/ruby'
hljs.registerLanguage('ruby', ruby)
But it’s not valid when using importmap.
The best solution I have found was doing the following in my stimulus controller:
import hljs from 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.6.0/build/es/highlight.min.js';
import ruby from 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.6.0/build/es/languages/ruby.min.js';
hljs.registerLanguage("ruby", ruby)
Do you know if there is any way to use this syntax with importmap: import hljs from "highlight.js/lib/core"?