kaisermann / svelte-loadable

Dynamically load a svelte component
MIT License
322 stars 13 forks source link

Import from url ? #33

Closed infuzz closed 4 years ago

infuzz commented 4 years ago

Hi, This is not a bug, but a noob question...

I tried to use svelte-loadable with a remote svelte component by passing an url in import attribute (ie : https://mydomain.com/mytest.svelte ) The component is well fetched (seen in network tabs dev tools, with its content) but I got an error :

Failed to load module script: The server responded with a non-JavaScript MIME type of "application/octet-stream". Strict MIME type checking is enforced for module scripts per HTML spec.
Loadable.svelte:137

Uncaught (in promise) TypeError: Failed to fetch dynamically imported module: https://mydomain.com/mytest.svelte
async function (async)
(anonymous) @ Loadable.svelte:130

I tried also to change the served mime type to javascript, but in this case, I got a bad token '<' error in console as browser is waiting to get a javascript file rather that an html svelte component....

Do you have any suggestion ?

kaisermann commented 4 years ago

Hey, @infuzz 👋 The component must be compiled previously. If you want to import a file from a remote endpoint, make sure the file is already in its compiled JS format and you should be good to go!