-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug?]: TypeError: Failed to fetch dynamically imported module #9352
Comments
Hey @pvenable
As far as I understand the issue, this is pretty much exactly it. It's a real bug and we've had two reports of it internally. Here's the associated Vite issue: vitejs/vite#11804. The workaround we've seen a user use is the one mentioned in the comment here: vitejs/vite#11804 (comment).
I'll bring this up to the team next week. If you ask me, I feel like the framework should handle it. The alternative is expecting pretty much every user to hack their FatalErrorPage to check |
Internally we are escalating this issue as a top priority. Because the core problem is upstream (Vite), we're in a bit of a catch-22 — most likely this will be a two-step process:
If you have ideas/suggestions/expectations about how you'd like to handle the case where a) client chunks are b) out of sync with newly deployed chunks, please comment below! WorkaroundYou can manually resolve the production error by forcing the window to reload. Add the code below to // web/src/pages/FatalErrorPage/FatalErrorPage.tsx|jsx
...
import { DevFatalErrorPage } from '@redwoodjs/web/dist/components/DevFatalErrorPage'
export default DevFatalErrorPage ||
(({ error }) => {
if (
error?.message?.includes(
'Failed to fetch dynamically imported module'
) &&
!window.location.href.includes('reload=1')
) {
if (window.location.href.includes('?')) {
window.location.href = window.location.href + '&reload=1'
} else {
window.location.href = window.location.href + '?reload=1'
}
return
}
return (
<main>
<style
...
/>
<section>
<h1>
<span>Something went wrong</span>
</h1>
</section>
</main>
)
}) You may need to modify the error check behavior per your application's unique implementation. Here's an alternate approach that's also working in production:
If you find a solution that works better for your app, please share it in the comments. |
Update: This is a priority for the Core Team. We have a meeting scheduled for Wednesday where we will discuss what the next step should be |
@ManavDia I'm not sure that's the exact same error as this issue is about. Could you please try to provide us with a github repo we can clone and clear instructions on how to reproduce? Thanks 🙏 |
Hello @Tobbe, were fixes for this issue released in newer versions of Redwood? we are still currently on v6 and getting this issue. |
Is there any update on this issue? We are experiencing it on v7. Thanks! |
Hello @elifkinli yes I found a plugin thats working great so far - https://www.npmjs.com/package/vite-plugin-preload |
@rohin-stafflink i am facing this issue in rails 7 while importing chart.js: |
@AfaqShahidKhan This thread is regarding Redwood JS, I'm unsure how to fix it in a rails repo sorry. |
@ManavDia thankyou sir. This code is working! |
What's not working?
We're seeing some errors in production like
TypeError: Failed to fetch dynamically imported module: <url>
, where<url>
will be something likehttps://example.com/assets/ExamplePage-e948e32f.js
.I suspect this mainly occurs on client navigation to a code-split page after a deployment where the chunk names have changed -- this looks like an issue with code splitting and "expected" chunks not being present in the newer deployment.
I'm not sure whether this would be considered a bug per se that redwood should handle out of the box, or whether this is up to each application to decide how to handle as a natural symptom of code splitting, so I was hoping to get some clarity on that if nothing else.
If it needs to be handled at the app level, I'm thinking catching the specific error on navigation and either "hard"-reloading or navigating to the destination path might be the way to go (depending on when exactly it occurs). I'm not sure yet if there are e.g. any navigation/router error hooks to tap into to that would simplify this.
I was also surprised to find no mention of this in any existing issues, so I'm not sure if this just isn't happening to others.
(FWIW I've also noticed what I think are similar errors in development since switching to vite in redwood 6, though the app seems to auto-reload when similar errors occur in development.)
How do we reproduce the bug?
I don't have an exact repro yet; I'll update this section later if possible. But I think it's basically: deploy new version of app and attempt client side navigation to request a now-missing chunk.
What's your environment? (If it applies)
Are you interested in working on this?
The text was updated successfully, but these errors were encountered: