# Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer: 错误：无法加载模块。无法加载所需模块 'dotnet.wasm'。

- **ID:** `dotnet/blazor-wasm-prerendering-chunk-load-failure`
- **领域:** dotnet
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| .NET 8.0 | active | — | — |
| Microsoft.AspNetCore.Components.WebAssembly 8.0.0 | active | — | — |
| Blazor WebAssembly 8.0 | active | — | — |

## 解决方案

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

## 无效尝试

- **** — Adding 'dotnet.wasm' to a custom bundler without proper WebAssembly MIME type mapping causes the browser to refuse the file. (65% 失败率)
- **** — Deleting the 'bin' and 'obj' folders and rebuilding may fix stale files but not underlying configuration issues like MIME types. (80% 失败率)
- **** — Disabling prerendering entirely (e.g., removing 'RenderMode.InteractiveWebAssembly') avoids the symptom but loses SEO and performance benefits. (50% 失败率)
