You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After updating to the newest SvelteKit yesterday, my app fails to load. I’m using adapter-static to generate a SvelteKit app that’s hosted by my company’s CDN. Once it's hosted there, I've been getting this error in Chrome:
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of “application/octet-stream”. Strict MIME type checking is enforced for module scripts per HTML spec.
caught (in promise) TypeError: Failed to fetch dynamically imported module: https://…/_app/immutable/entry/start.bbece0d7.mjs
As an alternative, SvelteKit could output all its built JavaScript as .js files. There’s not really any reason to use .mjs; browsers don’t know or care about file extensions, only Content-Type headers, and CDNs and servers like Apache and Nginx are very likely to serve .js files with a JavaScript MIME type. Have the build script output build/package.json that contains {"type": "module"} and the build output can be run by Node as well without issues.
Just use adapter-static as your adapter and run npm run build. All the JavaScript files inside build/ will have .mjs extensions.
Logs
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "application/octet-stream". Strict MIME type checking is enforced for module scripts per HTML spec.
Uncaught (in promise) TypeError: Failed to fetch dynamically imported module: https://<omitting…>/_app/immutable/entry/start.bbece0d7.mjs
// we use .mjs for client-side modules, because this signals to Chrome (when it
// reads the <link rel="preload">) that it should parse the file as a module
// rather than as a script, preventing a double parse. Ideally we'd just use
// modulepreload, but Safari prevents that
But I don’t know where this information comes from; it conflicts with my understanding of how browsers determine whether to treat a JavaScript URL as a module. cc @Rich-Harris as you apparently wrote these comments, and made these changes 4 days ago. I’d guess that #8957 is what broke my site.
The text was updated successfully, but these errors were encountered:
Describe the bug
After updating to the newest SvelteKit yesterday, my app fails to load. I’m using
adapter-static
to generate a SvelteKit app that’s hosted by my company’s CDN. Once it's hosted there, I've been getting this error in Chrome:Apparently my CDN doesn’t know that
.mjs
files need to be served with theContent-Type
headertext/javascript
. (See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#aside_%E2%80%94_.mjs_versus_.js.) While this is unfortunate, I’m not in a position to fix a bug in my company’s CDN.As an alternative, SvelteKit could output all its built JavaScript as
.js
files. There’s not really any reason to use.mjs
; browsers don’t know or care about file extensions, onlyContent-Type
headers, and CDNs and servers like Apache and Nginx are very likely to serve.js
files with a JavaScript MIME type. Have the build script outputbuild/package.json
that contains{"type": "module"}
and the build output can be run by Node as well without issues.Reproduction
https://stackblitz.com/edit/sveltejs-kit-template-default-8dvxxy?file=svelte.config.js&terminal=dev
Just use
adapter-static
as your adapter and runnpm run build
. All the JavaScript files insidebuild/
will have.mjs
extensions.Logs
System Info
Severity
blocking an upgrade
Additional Information
I see these mentions of
.mjs
in the SvelteKit code:kit/packages/kit/src/runtime/server/page/render.js
Lines 276 to 279 in 8c21383
kit/packages/kit/src/exports/vite/index.js
Lines 519 to 522 in 8c21383
But I don’t know where this information comes from; it conflicts with my understanding of how browsers determine whether to treat a JavaScript URL as a module. cc @Rich-Harris as you apparently wrote these comments, and made these changes 4 days ago. I’d guess that #8957 is what broke my site.
The text was updated successfully, but these errors were encountered: