fresh icon indicating copy to clipboard operation
fresh copied to clipboard

Importing modules using import maps in the client

Open dkolba opened this issue 2 years ago • 1 comments

Is it supported to use <script type="importmap"> within a component during development?

I always get An import map is added after module script load was triggered. in the browser console while running in dev mode. Import maps seem to expect to be loaded before everything else on the page and fresh_dev_client.js is always the very first script being loaded.

        <script
          type="importmap"
          dangerouslySetInnerHTML={{
            __html: '{ "imports": { "a": "/a.js"} }',
          }}
        />
        <script
          type="module"
          dangerouslySetInnerHTML={{
            __html: `
              import { a } from "a";
            `,
          }}
        />

dkolba avatar Dec 23 '23 13:12 dkolba

This is resolved in Fresh 2 as we don't load any scripts in <head> by default but at the end at </body> instead. This allows you to add an import map earlier.

marvinhagemeister avatar May 12 '25 19:05 marvinhagemeister