failed to fetch dynamically imported module in vercel deployment
See original GitHub issueDescribe the bug
I’m trying to dynamically import components in my SvelteKit app. It works fine in development mode but when I deploy to Vercel, it breaks.
The paths for the loaded files is here. I then import the data in this component where I map over them here.
I’m not sure why this is happening but I have no issues doing this on local dev. Only in prod does it break.
Reproduction
I don’t have any particular set of steps other than the files I linked above and the methods I used there.
Logs
GET https://www.jannatinnaim.com/_app/immutable/components/pages/_SocialSectionGitHub.svelte net::ERR_ABORTED 404
Uncaught (in promise) TypeError: Failed to fetch dynamically imported module: https://www.jannatinnaim.com/_app/immutable/components/pages/_SocialSectionGitHub.svelte
System Info
System:
OS: macOS 13.0.1
CPU: (10) arm64 Apple M1 Pro
Memory: 128.95 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.17.1 - ~/.asdf/installs/nodejs/16.17.1/bin/node
Yarn: 1.22.19 - ~/.asdf/installs/nodejs/16.17.1/bin/yarn
npm: 8.19.2 - ~/.asdf/plugins/nodejs/shims/npm
Browsers:
Chrome: 107.0.5304.87
Edge: 107.0.1418.35
Firefox: 106.0.5
Safari: 16.1
npmPackages:
@sveltejs/adapter-auto: next => 1.0.0-next.87
@sveltejs/kit: next => 1.0.0-next.539
svelte: ^3.44.0 => 3.52.0
vite: ^3.1.0 => 3.2.2
Severity
serious, but I can work around it
Additional Information
No response
Issue Analytics
- State:
- Created 10 months ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Failed to fetch dynamically imported module : r/sveltejs - Reddit
It works as expected locally in dev and preview. The problem is that when deployed to Vercel (https://sveltekit-firebase-ssr.vercel.app/) SSR ...
Read more >Failed to fetch dynamically imported module" on Vue/Vite ...
In my case the error was caused by not adding .vue extension to module name. import MyComponent from 'components/MyComponent'.
Read more >Failed to fetch dynamically imported module | Blazor Forums
Unhandled exception rendering component: Failed to fetch dynamically imported module: https://####.net/_content/Syncfusion.
Read more >vite failed to fetch dynamically imported module - You.com
I had the exact same issue. In my case some routes worked and some didn't. The solution was relatively easy. I just restarted...
Read more >Advanced Features: Dynamic Import - Next.js
Dynamically import JavaScript modules and React Components and split your code into manageable chunks.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This isn’t related to
adapter-vercel
. The problem is that the request is made relative to the current file, and those files live somewhere else to each other on prod. You can observe the same behavior when runningpreview
afterbuild
locally. Instead, you should make the dynamic import so that Vite can determine the correct path from it. In_Social.svelte
, do this:More info about dynamic imports in the context of Vite: https://vitejs.dev/guide/features.html#dynamic-import
I see. Thanks for the help.