dotnet runtime_error ai_generated true

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer: Error: Failed to load module. The required module 'dotnet.wasm' could not be loaded.

ID: dotnet/blazor-wasm-prerendering-chunk-load-failure

Also available as: JSON · Markdown · 中文
85%Fix Rate
82%Confidence
1Evidence
2024-01-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
.NET 8.0 active
Microsoft.AspNetCore.Components.WebAssembly 8.0.0 active
Blazor WebAssembly 8.0 active

Root Cause

Blazor WebAssembly prerendering fails when the browser cannot fetch 'dotnet.wasm' due to incorrect static file serving, missing MIME types, or network issues during initial load.

generic

中文

当浏览器由于静态文件服务配置错误、缺少 MIME 类型或初始加载期间网络问题而无法获取 'dotnet.wasm' 时,Blazor WebAssembly 预渲染失败。

Official Documentation

https://learn.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/webassembly?view=aspnetcore-8.0#configure-the-server

Workarounds

  1. 85% success Ensure the server sets the correct MIME type for .wasm files: in IIS, add 'application/wasm' MIME type; in Kestrel, it's automatic but verify via browser DevTools network tab. Also check that 'app.UseStaticFiles()' is called before endpoint routing.
    Ensure the server sets the correct MIME type for .wasm files: in IIS, add 'application/wasm' MIME type; in Kestrel, it's automatic but verify via browser DevTools network tab. Also check that 'app.UseStaticFiles()' is called before endpoint routing.
  2. 80% success If using a CDN or reverse proxy, ensure it passes through WebAssembly files. Add a rewrite rule: 'AddType application/wasm .wasm' in Apache or 'application/wasm' MIME map in Nginx.
    If using a CDN or reverse proxy, ensure it passes through WebAssembly files. Add a rewrite rule: 'AddType application/wasm .wasm' in Apache or 'application/wasm' MIME map in Nginx.

中文步骤

  1. 确保服务器为 .wasm 文件设置正确的 MIME 类型:在 IIS 中添加 'application/wasm' MIME 类型;在 Kestrel 中自动处理,但通过浏览器 DevTools 网络选项卡验证。同时检查是否在端点路由之前调用了 'app.UseStaticFiles()'。
  2. 如果使用 CDN 或反向代理,确保其透传 WebAssembly 文件。在 Apache 中添加重写规则:'AddType application/wasm .wasm',或在 Nginx 中添加 'application/wasm' MIME 映射。

Dead Ends

Common approaches that don't work:

  1. 65% fail

    Adding 'dotnet.wasm' to a custom bundler without proper WebAssembly MIME type mapping causes the browser to refuse the file.

  2. 80% fail

    Deleting the 'bin' and 'obj' folders and rebuilding may fix stale files but not underlying configuration issues like MIME types.

  3. 50% fail

    Disabling prerendering entirely (e.g., removing 'RenderMode.InteractiveWebAssembly') avoids the symptom but loses SEO and performance benefits.