You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Blazor中使用npm与Snowpack遇模块解析错误及构建异常求助

Blazor 中使用 npm 和 Snowpack 遇到的模块导入错误

主要错误:lodash 模块解析失败

按照指引在 Blazor 中集成 npm 和 Snowpack 时,导入 bundle 触发以下 JSInterop 异常:

Microsoft.JSInterop.JSException: Failed to resolve module specifier "lodash". Relative references must start with either "/", "./", or "../".
TypeError: Failed to resolve module specifier "lodash". Relative references must start with either "/", "./", or "../".
   at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
   at BlazorApp2.Components.Pages.Home.OnAfterRenderAsync(Boolean firstRender) in C:\Users\user\source\repos\BlazorApp2\BlazorApp2\Components\Pages\Home.razor:line 10
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

次要错误:Snowpack 构建时文件缺失

构建过程中出现文件找不到的错误,将 Snowpack 版本降级至 3.0.13 即可解决:

[@snowpack/plugin-optimize] Error: ENOENT: no such file or directory, open 'C:\Users\user\source\repos\BlazorApp2\BlazorApp2\wwwroot\js\_snowpack\optimize-manifest.json'
1>C:\Users\user\source\repos\BlazorApp2\BlazorApp2\BlazorApp2.csproj(10,3): error MSB3073: The command "cd JS && npm run snowpack-build" exited with code 1.

相关代码示例可参考对应仓库内容。


内容的提问来源于stack exchange,提问作者ScottexBoy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 01:14:57