Skip to content

[Blazor WebAssembly]Failed to fetch dynamically imported module #633

@wu-yafeng

Description

@wu-yafeng

Step to reproduce:

  1. dotnet new blazorwasm -n test01
  2. cd test01
  3. dotnet add package Fido2.BlazorWebAssembly --version 4.0.0
  4. update your Program.cs
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using test01;
+ using Fido2.BlazorWebAssembly;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
+ builder.Services.AddWebAuthn();
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

await builder.Build().RunAsync();
  1. update your Pages/Counter.razor
@page "/counter"
+ @using Fido2.BlazorWebAssembly
+ @inject WebAuthn WebAuthn

<PageTitle>Counter</PageTitle>

<h1>Counter</h1>

<p role="status">Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
    private int currentCount = 0;
- private void IncrementCount()
+ private async Task IncrementCount()
    {
+      await WebAuthn.Init(); // Failed to fetch dynamically imported module
        currentCount++;
    }
}
  1. dotnet run
Image

console logs:


Failed to load resource: the server responded with a status of 404 (Not Found)

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Failed to fetch dynamically imported module: http://localhost:5272/_content/Fido2.BlazorWebAssembly/js/WebAuthn.js
      TypeError: Failed to fetch dynamically imported module: http://localhost:5272/_content/Fido2.BlazorWebAssembly/js/WebAuthn.js
Microsoft.JSInterop.JSException: Failed to fetch dynamically imported module: http://localhost:5272/_content/Fido2.BlazorWebAssembly/js/WebAuthn.js
TypeError: Failed to fetch dynamically imported module: http://localhost:5272/_content/Fido2.BlazorWebAssembly/js/WebAuthn.js
   at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__23`1[[Microsoft.JSInterop.IJSObjectReference, Microsoft.JSInterop, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext()
   at Fido2.BlazorWebAssembly.WebAuthn.<>c__DisplayClass2_0.<<-ctor>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at test01.Pages.Counter.IncrementCount() in C:\Users\wuyafe10\source\repos\wu-yafeng\sample\src\test01\Pages\Counter.razor:line 18
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions