question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

failed to fetch dynamically imported module in vercel deployment

See original GitHub issue

Describe 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:closed
  • Created 10 months ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
dummdidummcommented, Nov 15, 2022

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 running preview after build locally. Instead, you should make the dynamic import so that Vite can determine the correct path from it. In _Social.svelte, do this:

  const getSectionComponent = () => {
      return import(`./_SocialSection${selectedSection}.svelte`).then((component) => component.default);
  };

More info about dynamic imports in the context of Vite: https://vitejs.dev/guide/features.html#dynamic-import

0reactions
jNaimXIIIcommented, Nov 15, 2022

I see. Thanks for the help.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found