Strapi Admin Module Loading#
The Strapi admin panel is a Vite-bundled SPA served by a Node.js/Koa server. Route pages and plugin UI are delivered as dynamically-imported, code-split chunks requested by the browser on demand. A recurring class of runtime failures ā TypeError: Failed to fetch dynamically imported module ā occurs when the browser requests a chunk that is no longer available at the URL it expects. Understanding how chunks are generated, served, and cached is the key to diagnosing and resolving these failures.
How the Admin Loads Modules at Runtime#
Entry generation. At startup, Strapi scans enabled plugins for an admin entry point (strapi-admin export) and generates two files into .strapi/client/: index.html (the shell) and app.js (the entry module). The generated app.js statically imports each plugin's admin entry and calls renderAdmin with the full plugin map . Plugin admin code therefore enters the Vite module graph at startup ā not at browser request time.
Dynamic chunks. Within the admin shell, every route page is registered as a React Router lazy route. When a user navigates to a route, React Router calls the lazy function, which triggers a dynamic import(). Vite serves that request as a hashed chunk (e.g., Layout-BNnc9GRt.js, App-BFYAelNz.js, EditViewPage-PrPHZN_9-AY5UZTDL.js).
Dev vs. production serving. In development, Vite runs in middleware mode, mounted on Strapi's Koa HTTP server. The Koa layer strips the base path and passes module/chunk requests to vite.middlewares . All dev responses carry Cache-Control: no-store headers to prevent stale-chunk problems during restarts . In production, the compiled static output is served by serve-admin-panel.ts: index.html is served with no-cache, while all hashed assets get public, max-age=31536000, immutable .
Vite dependency cache (node_modules/.strapi/vite). Strapi sets cacheDir: 'node_modules/.strapi/vite' . Vite writes pre-optimized dependency chunks under node_modules/.strapi/vite/deps/. These chunks are named with a hash suffix (e.g., EditViewPage-PrPHZN_9-AY5UZTDL.js?v=1e16bab9) and are referenced by import maps embedded in the HTML. If the cache is invalidated (by a config or dependency change) but a browser tab still holds the old import map, the next navigation triggers a fetch for a URL that no longer exists.
Chunk Load Failures: Causes and Patterns#
The error TypeError: Failed to fetch dynamically imported module surfaces in two distinct contexts:
1. Stale hashed chunks after a deploy (production). When a new build is deployed, all output files get new content-hashes (e.g., Layout-BNnc9GRt.js ā Layout-XYZ.js). A browser tab opened before the deploy still holds the old HTML with references to the old chunk URLs. On the next navigation, the old URLs return 404 ā triggering the error. Issues #27657 (Strapi Cloud, Settings page) , #27800 (Render) , and #27338 (Railway) all show this pattern in hosted deployments. The fix is to reload the browser tab after a deploy ā there is no workaround that avoids it.
2. Stale Vite dep-cache chunks after a config or locale change (development). Strapi caches pre-bundled dependency chunks in node_modules/.strapi/vite/deps/. Vite invalidates this cache when it detects a change to vite.config, package.json, or optimizeDeps settings ā and rewrites the import map with new chunk names. If the browser has an open tab with the old import map (from before the change), it fetches the old chunk URLs from the new cache, which no longer contain them. Issue #27949 explicitly shows this pattern after changing the default i18n locale: the failed URL points directly into node_modules/.strapi/vite/deps/EditViewPage-PrPHZN_9-AY5UZTDL.js?v=1e16bab9 .
Retry Mechanism#
The admin has a built-in retry layer for transient chunk failures. retryDynamicImport.ts provides:
isChunkLoadError(error)ā detects the failure by matching a cross-browser regex against error messages and names .retryDynamicImport(importer, options)ā retries theimport()up to 6 times with exponential backoff (400 ms initial, 4.5 s max) plus jitter . This handles transient network blips where the host is cold or a connection drops.wrapRouteObjectsLazyWithRetry(routes)ā wraps everylazyloader on the React Router route tree so all routes benefit automatically .
Limitation: Retry does not fix a permanent 404 for a stale chunk after a deploy. The code comment is explicit: "Does not fix a permanent 404 for a stale chunk after deploy ā isChunkLoadError still surfaces; use ErrorElement reload for that case" . For permanent failures, the error boundary should prompt the user to hard-reload.
Diagnosis and Workarounds#
Identify the failure context from the URL:
| URL pattern | Likely cause |
|---|---|
/admin/Layout-<hash>.js, /admin/App-<hash>.js | Stale hashed chunk ā browser tab predates a deploy |
/node_modules/.strapi/vite/deps/<name>-<hash>.js?v=<hash> | Stale Vite dep-cache chunk ā config/dependency change invalidated the cache |
Production (stale chunk after deploy): Hard-reload the browser tab (Ctrl+Shift+R / Cmd+Shift+R) or navigate fresh. For CDN/proxy deployments, ensure the old build assets remain accessible for a short grace period, or configure your CDN to purge only after all open sessions drain.
Development (stale Vite dep-cache):
- Hard-reload the browser tab. The new import map is embedded in the re-served
index.html. - If that doesn't help, stop the server, delete
node_modules/.strapi/vite, and restart. Vite will rebuild the dep cache from scratch. - When a config change (e.g., locale settings,
optimizeDeps) triggers repeated cache invalidation, add the affected packages tooptimizeDeps.includeinsrc/admin/vite.config.tsto stabilize the cache. See Vite Build Configuration for the pattern.
Note: Strapi's dev middleware already sets Cache-Control: no-store on all admin responses , so browser caching is not the cause in development mode.
Key Files#
| File | Role |
|---|---|
node/vite/config.ts | Sets cacheDir: 'node_modules/.strapi/vite'; configures optimizeDeps.include, resolve.dedupe, and resolve.alias |
node/vite/watch.ts | Mounts Vite in middleware mode on Koa; sets no-store cache headers for all dev admin responses |
node/staticFiles.ts | Generates .strapi/client/app.js (plugin entry module) and index.html at startup |
admin/server/src/routes/serve-admin-panel.ts | Production static file serving: no-cache for HTML, immutable for hashed assets |
admin/admin/src/router.tsx | Defines all admin routes as React Router lazy imports (code-split chunks) |
admin/admin/src/utils/retryDynamicImport.ts | Exponential-backoff retry for transient chunk load failures |
See Also#
- Vite Build Configuration ā
optimizeDeps,resolve.dedupe, andresolve.aliassetup that controls which packages enter the dep cache - Monorepo Module Resolution ā pnpm/strict-layout failures that can produce blank admin panels from duplicate package instances