500: Failed to fetch dynamically imported module
Describe the bug
I am encountering some issues when deploying my project to vercel using the vercel-adapter. The project builds but then the deployed site I receive 500 Failed to fetch dynamically imported module: https://xxx.vercel.app/_app/undefined
The vercel build is triggered by a new Gitlab commit.
Does someone have an idea what could cause this issue? The weird thing is that it works with npm run build but not on the deployed vercel site...
Reproduction
This should be reproducable by using the same sveltekit + adapter versions
Logs
No response
System Info
System:
OS: Windows 10 10.0.19044
CPU: (8) x64 Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
Memory: 13.49 GB / 31.91 GB
Binaries:
Node: 16.13.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 8.3.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 97.0.4692.71
Edge: Spartan (44.19041.1266.0), Chromium (97.0.1072.55)
Internet Explorer: 11.0.19041.1202
npmPackages:
@sveltejs/adapter-auto: next => 1.0.0-next.10
@sveltejs/adapter-vercel: next => 1.0.0-next.36
@sveltejs/kit: ^1.0.0-next.225 => 1.0.0-next.225
svelte: ^3.46.0 => 3.46.0
Severity
blocking all usage of SvelteKit
Additional Information
No response
Having the same issue with cloudflare adapter, but just on reload.
This should be reproducable by using the same sveltekit + adapter versions
I don't think this happens with all projects or we'd probably be getting a whole lot more bug reports. Can you make it happen with a brand new project? If not, can you provide a project that reproduces it?
Thanks, @benmccann! Yes, you are probably right - sorry for my assumption. I am trying to work out how to reproduce it and will update you further.
Additionally I have noticed, the first error I receive when loading the page is: 500: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of URL. Received undefined and after that reload it is the error mentioned above.
But of course I understand that it is hard for you to reproduce it like that. I was just hoping that someone has already experienced the same issue and has a solution. I will keep you updated. Thank you!
Here is the repo: https://github.com/mawoka-myblock/svelte-cf-error And I deployed it for testing reasons here (ofc with cf-pages): https://svelte-cf-error.pages.dev/blog/test If you visit the link directly, you'll get a 500 document undefined (Any tips here are really appreciated), but if you go to https://svelte-cf-error.pages.dev/blog and then open the blog-post, it works until you reload. The first reload will produce a 500 document not defined error and the 2nd reload the error this issue is about.
Just for a small bit of added context, we are deployed to our own VMs on Digital Ocean (plain old node adapter) and see this error in the logs approximately 1-2 per week. Still trying to gather enough of the situation to share. :(
@benmccann It also happens on/with the clodflare-pages adapter
Getting the same error on a hello world app: https://github.com/ManuelDeLeon/sveltekit-firebase-ssr
It works as expected locally in dev and preview.
The problem is that when deployed to Vercel (https://sveltekit-firebase-ssr.vercel.app/) SSR doesn't work (page source isn't what's expected), an error flashes, and the console shows another error.
Error on page:
Failed to fetch dynamically imported module: https://sveltekit-firebase-ssr.vercel.app/_app/undefined
Error in console
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
Vercel works for me fine, but Cloudflare-Pages doesn't
Just hit the same error with Cloudflare pages. If you visit the link directly, you get a 500: Failed to fetch dynamically imported module: https://fef7dft46.*********.pages.dev/_app/undefined. It only happens with some pages though, not all.
It turns out that in my case, it was because I had to dynamically load certain modules that are only for browsers inside onMount.
This is actually something we see daily and it's been driving me nuts because I can't seem to find the root cause. In one user session just a bit ago this happened.
TypeError: Failed to fetch dynamically imported module: https://that.us/_app/pages/activities/__layout.svelte-f2da0de0.js
then
TypeError: Failed to fetch dynamically imported module: https://that.us/_app/pages/activities/create/__layout.svelte-64778a6f.js
then
TypeError: Failed to fetch dynamically imported module: https://that.us/_app/pages/activities/create/cfp.svelte-11144fe2.js
Which lead to the 500. I've long thought it was vercel just not rendering those files or an ad tracker but I would love to fix it. Any ideas on how to hunt down the why on this?
This is actually something we see daily and it's been driving me nuts because I can't seem to find the root cause. In one user session just a bit ago this happened.
TypeError: Failed to fetch dynamically imported module: https://that.us/_app/pages/activities/__layout.svelte-f2da0de0.js then TypeError: Failed to fetch dynamically imported module: https://that.us/_app/pages/activities/create/__layout.svelte-64778a6f.js then TypeError: Failed to fetch dynamically imported module: https://that.us/_app/pages/activities/create/cfp.svelte-11144fe2.jsWhich lead to the 500. I've long thought it was vercel just not rendering those files or an ad tracker but I would love to fix it. Any ideas on how to hunt down the why on this?
Change to another adapter! The problem may occur only with the vercel adapter, or just with the cloudflare adapter
Change to another adapter! The problem may occur only with the vercel adapter, or just with the cloudflare adapter
Well, I've used both the auto adapter and the vercel one. I'm not picking up and moving off of vercel, unless that's really the issue which means a huge infrastructure change. Now our vercel setup is behind cloudflare and set up the way they recommend.
You can just deploy it as a test to cloudflare, shouldn't take long and if the issue is still there, it's probably in your code and if not, this issue is the right place!
You can just deploy it as a test to Cloudflare, shouldn't take long and if the issue is still there, it's probably in your code and if not, this issue is the right place!
I can't even consistently reproduce it, without being able to do that moving it doesn't make any sense. If I could repo or knew how to, I would know where to start looking.
On top of that, it's never "just" a just and our site isn't small http://github.com/ThatConference/that.us
I think that this error might arise whenever you push a new update to the site, which causes a re-built of all modules. In the rebuilt, all files get a new name. If the user was already on the website and doesn't hit rephresh, navigating in the website will eventually try to load a module that is no longer there, causing an error.
I think that this error might arise whenever you push a new update to the site, which causes a re-built of all modules. In the rebuilt, all files get a new name. If the user was already on the website and doesn't hit rephresh, navigating in the website will eventually try to load a module that is no longer there, causing an error.
Good point! I think we are having many different issues in this issue, which all lead to the sane error. For me, I fixed my website, by switching to vercel, away from cloudflare.
I think that this error might arise whenever you push a new update to the site, which causes a re-built of all modules. In the rebuilt, all files get a new name. If the user was already on the website and doesn't hit rephresh, navigating in the website will eventually try to load a module that is no longer there, causing an error.
Yes, I think that's likely and could cause this error. That should be fixed by https://github.com/sveltejs/kit/pull/3412. Can folks report whether this issue is fixed by 1.0.0-next.254 or still occuring?
I think that this error might arise whenever you push a new update to the site, which causes a re-built of all modules. In the rebuilt, all files get a new name. If the user was already on the website and doesn't hit rephresh, navigating in the website will eventually try to load a module that is no longer there, causing an error.
That sounds plausible, but could be refuted by our experience. We see this error type ~ one a week and our sessions are incredibly short-lived, certainly much shorter than our deploy cycle. Also, we are using the node adaptor.
We will try to report findings once upgraded to 254. Thanks!
Yes, I think that's likely and could cause this error. That should be fixed by #3412. Can folks report whether this issue is fixed by
1.0.0-next.254or still occurring?
@benmccann looks like I am on 204
having said that I am working through updating 254. Just trying to make my way through some of the breaking changes. Hoping to get that out maybe this morning.