mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-03 21:25:13 +00:00
Blazor Web App (.net8) - error: Cannot resolve '_blazor' when started by - electronize start #921
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Elangovan4ever on GitHub (Nov 15, 2023).
.Net Version: Net8.0
ElectronNET.API: 23.6.1
ElectronNET.CLI Version: 23.6.1.0
.Net Version: Net8.0
Node.js version: v18.15.0
Windows 10 Enterprise
Windows 11 Pro
Tried in both windows versions.
Issue:
When I run the blazor web app through electronize start command, the app starts in electron window, but no click event works. In the dev tools console window it shows the error as "blazor.web.js:1 Uncaught (in promise) Error: Cannot resolve '_blazor'.".
Test Project on GitHub: https://github.com/elandev4ever/SimpleBlazorWebApp
Steps to Reproduce:
dotnet tool install ElectronNET.CLI -g
electronize init
electronize start
blazor.web.js:1 Uncaught (in promise) Error: Cannot resolve '_blazor'.
at xn._resolveUrl (blazor.web.js:1:93927)
at new xn (blazor.web.js:1:83462)
at Ln.build (blazor.web.js:1:99418)
at Oo.startConnection (blazor.web.js:1:135970)
at Oo.startCore (blazor.web.js:1:135408)
at Oo.start (blazor.web.js:1:135061)
at nr (blazor.web.js:1:151076)
Note: this issue might be related to the render modes that are introduced in .Net8. If I keep the render mode per page, and then remove the render mode attribute from razor page the error is not shown in console, but still the button click wont work because of no render mode.
since .net 8 just made official today, I guess the support for this might not exist yet. Until this sorted out, any temporary workaround would be great.
@peter-bozovic commented on GitHub (Dec 2, 2023):
Same issue here ...
Blazor Server project that was working with net7, just changed the TargetFramework to net8 and have the same error !
Hope that can be fixed so that we can migrate to the latest LTS dotnet
@rubenmonteiro commented on GitHub (Dec 3, 2023):
Hi all.
I have the same issue.
I created a project with the .net8 template "Blazor Web App", with auto render mode.
I was able to understand, at least in my case, that the framework inserts a file "_framework/blazor.web.js" on the site.
Besides other stuff done, this js file is responsible for creating websocket connections to the server.
The problem occurs in this creation.
The code in the js is the following, extracted from Developer tools created by Electron window
When this method is called, the parameter 'e' has the value '_blazor'
the problem is in the condition 'if (!Wt.isBrowser)', this condition returns false the anchor tag is not generated to return the href necessary.
the code of the Wt class is this one
class Wt { static get isBrowser() { return !Wt.isNode && "object" == typeof window && "object" == typeof window.document } static get isWebWorker() { return !Wt.isNode && "object" == typeof self && "importScripts"in self } static get isReactNative() { return !Wt.isNode && "object" == typeof window && void 0 === window.document } static get isNode() { return "undefined" != typeof process && process.release && "node" === process.release.name } }the method isBrowser returns false because the condition in the method isNode is true.
If there is a way in Electron to set the process release name to something different to the value 'node' it could work, because the process class in the browser, chrome, edge, etc is undefined.
I don't know if this is related
Code in aspnetcore repo
this is the same condition
@peter-bozovic commented on GitHub (Dec 3, 2023):
Thank you @rubenmonteiro for the deep dive into the source code of the issue !
So, the workaround that seem to work is to add
<script>process = undefined;</script>just before the
<script src="_framework/blazor.web.js"></script>@rubenmonteiro commented on GitHub (Dec 3, 2023):
I will test and give the feedback.
I was searching for a workaround also.
@rubenmonteiro commented on GitHub (Dec 3, 2023):
@peter-bozovic it seems to work, no issue found until now. thanks for the tip, the workarounds I thought were a lot more complicated then this
@kenZhou2 commented on GitHub (Jan 10, 2024):
@peter-bozovic does anyone have any issue running the windows exe on release or debug? It seems that electron isnt being read
@datttit commented on GitHub (Sep 23, 2024):
I love you so much.
This issue take to me about 3 working hour but not working.
I'm using mudblazor and electron.
Thank you so much!
@tonsnoei commented on GitHub (Nov 2, 2024):
Great work! Thanks! Just some additional info, the code is located in
_Host.cshtmland now it is calledblazor.server.jsinstead ofblazor.web.js@well0549 commented on GitHub (Nov 11, 2024):
Thanks this helped me too
@FlorianRappl commented on GitHub (Oct 31, 2025):
Outdated - use
ElectronNET.CoreandElectronNET.Core.AspNet.See Wiki / What's New.