WebUSB icon indicating copy to clipboard operation
WebUSB copied to clipboard

Could not find 'BlazorExtensions' in 'window'.

Open bzuidgeest opened this issue 5 years ago • 1 comments

I just installed the webusb extension in my first blazor project. Unfortunately it gives me this error on the console.

Similar errors in the issuelists of other blazor extensions lead me to believe that this is caused by newer versions of blazor breaking something related to static content. But nothing I found suggested worked for me.

As to recreate, I just started a new blazor app from the vs template and added the extension. I also added the code from this project its testpage.

blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Could not find 'BlazorExtensions' in 'window'. Error: Could not find 'BlazorExtensions' in 'window'. at https://localhost:44355/_framework/blazor.webassembly.js:1:9130 at Array.forEach () at p (https://localhost:44355/_framework/blazor.webassembly.js:1:9090) at https://localhost:44355/_framework/blazor.webassembly.js:1:9800 at new Promise () at Object.beginInvokeJSFromDotNet (https://localhost:44355/_framework/blazor.webassembly.js:1:9773) at _mono_wasm_invoke_js_marshalled (https://localhost:44355/_framework/wasm/dotnet.3.2.0.js:1:171294) at do_icall (https://localhost:44355/_framework/wasm/dotnet.wasm:wasm-function[6049]:0x10f8b1) at do_icall_wrapper (https://localhost:44355/_framework/wasm/dotnet.wasm:wasm-function[1896]:0x50b6a) at interp_exec_method (https://localhost:44355/_framework/wasm/dotnet.wasm:wasm-function[1120]:0x2588e) Microsoft.JSInterop.JSException: Could not find 'BlazorExtensions' in 'window'. Error: Could not find 'BlazorExtensions' in 'window'. at https://localhost:44355/_framework/blazor.webassembly.js:1:9130 at Array.forEach () at p (https://localhost:44355/_framework/blazor.webassembly.js:1:9090) at https://localhost:44355/_framework/blazor.webassembly.js:1:9800 at new Promise () at Object.beginInvokeJSFromDotNet (https://localhost:44355/_framework/blazor.webassembly.js:1:9773) at _mono_wasm_invoke_js_marshalled (https://localhost:44355/_framework/wasm/dotnet.3.2.0.js:1:171294) at do_icall (https://localhost:44355/_framework/wasm/dotnet.wasm:wasm-function[6049]:0x10f8b1) at do_icall_wrapper (https://localhost:44355/_framework/wasm/dotnet.wasm:wasm-function[1896]:0x50b6a) at interp_exec_method (https://localhost:44355/_framework/wasm/dotnet.wasm:wasm-function[1120]:0x2588e) at System.Threading.Tasks.ValueTask`1[TResult].get_Result () <0x2df6dd0 + 0x00034> in :0 at Blazor.Extensions.WebUSB.USB.Initialize () [0x00041] in /home/runner/work/WebUSB/WebUSB/src/Blazor.Extensions.WebUSB/USB.cs:78 at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask (System.Threading.Tasks.Task taskToHandle) <0x2db6878 + 0x000b6> in :0

bzuidgeest avatar Oct 25 '20 15:10 bzuidgeest

the nuget package doesn't seem to be exporting everything you should. When built manually the webpack outputs a blazor.extensions.webusb.js in the /dist folder. You need to load that script somehow in your application then you can use web usb.

gibetcher avatar Dec 20 '20 18:12 gibetcher