Mobile iOS Safari Errors - 500: Importing a module script failed.
See original GitHub issueDescribe the bug
I recently migrated my website from NextJS to SvelteKit.
Everything has worked smoothly except for mysterious errors that seem to happen mostly on mobile iOS Safari, but also on desktop Firefox.
On Safari, the error is: “500: Importing a module script failed.” On Firefox, the error is: “500: error loading dynamically imported module”

As you can see, this is so common that a total of 0.6% of visitors are getting a critical error that is severe enough to replace the entire page’s content with an error message.
On Safari, the error happens mostly on the home page. On Firefox there is no noticeable pattern. It appears to be a client-side error because my Vercel server logs are not picking up the errors.
I track the error by sending a custom event to Plausible Analytics in the __error.svelte file.
The error appears to be coming from up-to-date browser versions. As in, Safari 15 and Firefox 101.
Here’s the spike in errors after switching to SvelteKit:

Unfortunately, I am totally unable to replicate the error myself. It does not show up on my iPhone or the versions I tested with Browserstack. And there doesn’t appear to be any stack trace provided to help me debug the issue.
This is my site: https://stockanalysis.com/ This is the repo: https://github.com/stockanalysisdev/stock-analysis-sveltekit
Has anyone dealt with this issue before? Or have an idea about the best way to debug the issue without being able to reproduce it myself?
Also, if anyone could try visiting my home page on mobile iOS Safari and see whether they get an error and a stack trace then that would be incredibly helpful.
Reproduction
Unable to reproduce testing on my own iPhone or via Browserstack.
Logs
No response
System Info
All packages have been updated to their latest versions.
System:
OS: macOS 12.4
CPU: (10) x64 Apple M1 Pro
Memory: 333.49 MB / 32.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 17.9.0 - /usr/local/bin/node
npm: 8.8.0 - /usr/local/bin/npm
Browsers:
Brave Browser: 102.1.39.122
Chrome: 102.0.5005.115
Firefox: 101.0.1
Safari: 15.5
npmPackages:
@sveltejs/adapter-auto: 1.0.0-next.50 => 1.0.0-next.50
@sveltejs/kit: 1.0.0-next.350 => 1.0.0-next.350
svelte: ^3.48.0 => 3.48.0
Severity
blocking an upgrade
Additional Information
No response
Issue Analytics
- State:
- Created a year ago
- Comments:13 (4 by maintainers)
Top Related StackOverflow Question
I’m going to close this since the error rate has gone down significantly. It’s down to about 0.3% of visits, which is significant but not much higher than it was with NextJS.
I haven’t done anything specific that I belive can explain the drop in errors. They increased with Vite 3.0.0 but have gone down as of Vite 3.0.2. Not sure if that’s even related to the errors.
I don’t mean to beat a dead horse here, but my application is a PWA Svelte (but not SvelteKit) and getting these errors reported. I would imagine this may be still present in SvelteKit, but the reason I’m posting here is because a lot of my users are experiencing this error and I have no strings to pull on except in this thread. Does anyone understand why this is happening? Has anybody found a solution?