Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wasm: FS is not defined on .NET 7 #67290

Closed
Zhiyuan-Amos opened this issue Mar 29, 2022 · 6 comments
Closed

Wasm: FS is not defined on .NET 7 #67290

Zhiyuan-Amos opened this issue Mar 29, 2022 · 6 comments
Assignees
Labels
arch-wasm WebAssembly architecture area-VM-meta-mono
Milestone

Comments

@Zhiyuan-Amos
Copy link

Description

Directed here by Steve Sanderson.

Reproduction Steps

  1. Create a .NET 6.0 Blazor Wasm project by running dotnet new blazorwasm -f net6.0
  2. Create a .NET 7.0 Blazor Wasm project by running dotnet new blazorwasm
  3. For both projects, add the following code to Index.razor:
@code
{
    [Inject]
    private IJSRuntime _js { get; set; }

    protected override async Task OnInitializedAsync()
    {
        var module = await _js.InvokeAsync<IJSObjectReference>("import", "./fs.js");
        await module.InvokeVoidAsync("fs");
    }
}
  1. For both projects, create a new file fs.js in wwwroot and add the following code:
export function fs() {
    FS.analyzePath("dummy").exists;
}

Expected behavior

No errors thrown for both projects

Actual behavior

The project on .NET 7.0 throws the following error:

blazor.webassembly.js:1 
       crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: FS is not defined
      ReferenceError: FS is not defined
          at Module.fs (http://localhost:5236/fs.js:2:5)
          at http://localhost:5236/_framework/blazor.webassembly.js:1:3334
          at new Promise (<anonymous>)
          at Object.beginInvokeJSFromDotNet (http://localhost:5236/_framework/blazor.webassembly.js:1:3308)
          at Object.kt [as invokeJSFromDotNet] (http://localhost:5236/_framework/blazor.webassembly.js:1:59840)
          at Object.mono_wasm_invoke_js_blazor (http://localhost:5236/_framework/dotnet.7.0.0-preview.2.22152.2.36b1887bg5.js:3:53168)
          at _mono_wasm_invoke_js_blazor (http://localhost:5236/_framework/dotnet.7.0.0-preview.2.22152.2.36b1887bg5.js:13:111972)
          at http://localhost:5236/_framework/dotnet.wasm:wasm-function[266]:0x1b79c
          at http://localhost:5236/_framework/dotnet.wasm:wasm-function[237]:0x1ad97
          at http://localhost:5236/_framework/dotnet.wasm:wasm-function[177]:0xce51
Microsoft.JSInterop.JSException: FS is not defined
ReferenceError: FS is not defined
    at Module.fs (http://localhost:5236/fs.js:2:5)
    at http://localhost:5236/_framework/blazor.webassembly.js:1:3334
    at new Promise (<anonymous>)
    at Object.beginInvokeJSFromDotNet (http://localhost:5236/_framework/blazor.webassembly.js:1:3308)
    at Object.kt [as invokeJSFromDotNet] (http://localhost:5236/_framework/blazor.webassembly.js:1:59840)
    at Object.mono_wasm_invoke_js_blazor (http://localhost:5236/_framework/dotnet.7.0.0-preview.2.22152.2.36b1887bg5.js:3:53168)
    at _mono_wasm_invoke_js_blazor (http://localhost:5236/_framework/dotnet.7.0.0-preview.2.22152.2.36b1887bg5.js:13:111972)
    at http://localhost:5236/_framework/dotnet.wasm:wasm-function[266]:0x1b79c
    at http://localhost:5236/_framework/dotnet.wasm:wasm-function[237]:0x1ad97
    at http://localhost:5236/_framework/dotnet.wasm:wasm-function[177]:0xce51
   at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__16`1[[Microsoft.JSInterop.Infrastructure.IJSVoidResult, Microsoft.JSInterop, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext()
   at Microsoft.JSInterop.JSObjectReferenceExtensions.InvokeVoidAsync(IJSObjectReference jsObjectReference, String identifier, Object[] args)
   at FsRepo.Pages.Index.OnInitializedAsync() in C:\Users\zhiyu\Downloads\FsRepo\Pages\Index.razor:line 19
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

Regression?

.NET 6

Known Workarounds

No response

Configuration

No response

Other information

No response

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Mar 29, 2022
@radical radical added the arch-wasm WebAssembly architecture label Mar 29, 2022
@ghost
Copy link

ghost commented Mar 29, 2022

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Directed here by Steve Sanderson.

Reproduction Steps

  1. Create a .NET 6.0 Blazor Wasm project by running dotnet new blazorwasm -f net6.0
  2. Create a .NET 7.0 Blazor Wasm project by running dotnet new blazorwasm
  3. For both projects, add the following code to Index.razor:
@code
{
    [Inject]
    private IJSRuntime _js { get; set; }

    protected override async Task OnInitializedAsync()
    {
        var module = await _js.InvokeAsync<IJSObjectReference>("import", "./fs.js");
        await module.InvokeVoidAsync("fs");
    }
}
  1. For both projects, create a new file fs.js in wwwroot and add the following code:
export function fs() {
    FS.analyzePath("dummy").exists;
}

Expected behavior

No errors thrown for both projects

Actual behavior

The project on .NET 7.0 throws the following error:

blazor.webassembly.js:1 
       crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: FS is not defined
      ReferenceError: FS is not defined
          at Module.fs (http://localhost:5236/fs.js:2:5)
          at http://localhost:5236/_framework/blazor.webassembly.js:1:3334
          at new Promise (<anonymous>)
          at Object.beginInvokeJSFromDotNet (http://localhost:5236/_framework/blazor.webassembly.js:1:3308)
          at Object.kt [as invokeJSFromDotNet] (http://localhost:5236/_framework/blazor.webassembly.js:1:59840)
          at Object.mono_wasm_invoke_js_blazor (http://localhost:5236/_framework/dotnet.7.0.0-preview.2.22152.2.36b1887bg5.js:3:53168)
          at _mono_wasm_invoke_js_blazor (http://localhost:5236/_framework/dotnet.7.0.0-preview.2.22152.2.36b1887bg5.js:13:111972)
          at http://localhost:5236/_framework/dotnet.wasm:wasm-function[266]:0x1b79c
          at http://localhost:5236/_framework/dotnet.wasm:wasm-function[237]:0x1ad97
          at http://localhost:5236/_framework/dotnet.wasm:wasm-function[177]:0xce51
Microsoft.JSInterop.JSException: FS is not defined
ReferenceError: FS is not defined
    at Module.fs (http://localhost:5236/fs.js:2:5)
    at http://localhost:5236/_framework/blazor.webassembly.js:1:3334
    at new Promise (<anonymous>)
    at Object.beginInvokeJSFromDotNet (http://localhost:5236/_framework/blazor.webassembly.js:1:3308)
    at Object.kt [as invokeJSFromDotNet] (http://localhost:5236/_framework/blazor.webassembly.js:1:59840)
    at Object.mono_wasm_invoke_js_blazor (http://localhost:5236/_framework/dotnet.7.0.0-preview.2.22152.2.36b1887bg5.js:3:53168)
    at _mono_wasm_invoke_js_blazor (http://localhost:5236/_framework/dotnet.7.0.0-preview.2.22152.2.36b1887bg5.js:13:111972)
    at http://localhost:5236/_framework/dotnet.wasm:wasm-function[266]:0x1b79c
    at http://localhost:5236/_framework/dotnet.wasm:wasm-function[237]:0x1ad97
    at http://localhost:5236/_framework/dotnet.wasm:wasm-function[177]:0xce51
   at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__16`1[[Microsoft.JSInterop.Infrastructure.IJSVoidResult, Microsoft.JSInterop, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext()
   at Microsoft.JSInterop.JSObjectReferenceExtensions.InvokeVoidAsync(IJSObjectReference jsObjectReference, String identifier, Object[] args)
   at FsRepo.Pages.Index.OnInitializedAsync() in C:\Users\zhiyu\Downloads\FsRepo\Pages\Index.razor:line 19
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

Regression?

.NET 6

Known Workarounds

No response

Configuration

No response

Other information

No response

Author: Zhiyuan-Amos
Assignees: -
Labels:

arch-wasm, untriaged, area-VM-meta-mono

Milestone: -

@lewing
Copy link
Member

lewing commented Mar 29, 2022

I think your specific issue is probably fixed by #66868 but we'll have to test to be sure.

cc @pavelsavara

@lewing lewing removed the untriaged New issue has not been triaged by the area owner label Mar 30, 2022
@lewing lewing added this to the 7.0.0 milestone Mar 30, 2022
@Zhiyuan-Amos
Copy link
Author

Hello @lewing, just fyi, I am still able to reproduce this issue on .NET 7 Preview 3.

@pavelsavara
Copy link
Member

pavelsavara commented Apr 14, 2022

The dotnet wasm runtime does not spill it's guts to JS global namespace in Net 7.0.
But blazor still does publish it as window.Module.
Instead of FS.analyzePath try window.Module.FS.analyzePath see if that helps you.

@Zhiyuan-Amos
Copy link
Author

@pavelsavara that works, thank you!

@Zhiyuan-Amos Zhiyuan-Amos changed the title Wasm: FS is not defined on .NET 7 Preview 2 Wasm: FS is not defined on .NET 7 Apr 14, 2022
@ghost ghost locked as resolved and limited conversation to collaborators May 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-VM-meta-mono
Projects
None yet
Development

No branches or pull requests

5 participants