You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Blazor Web App (.net8) - error: Cannot resolve '_blazor' when started by - electronize start #823
Target:
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'.".
Create a "Blazor Web App" project in Visual studio 2022 version 17.8.0. Select "Net 8 Long Term Support" as framework while creating the project. Please note that for .Net8 Microsoft removed "Blazor Server" template and introduced "Blazor Web App" in project workloads. Now the Blazor script file also named "blazor.web.js" instead of "blazor.server.js".
Run from Visual Studio as web app. it runs fine. This is default app code which has a Counter page. In the counter page, click on "Click Me" button. The number increases as expected.
Added Nuget package "ElectronNET.API" to the project. Added electron create window code in program.cs [https://github.com/elandev4ever/SimpleBlazorWebApp/blob/master/SimpleBlazorWebApp/Program.cs]
In Windows Command prompt navigate to app folder, and run the following commands:
dotnet tool install ElectronNET.CLI -g
electronize init
electronize start
Application opens in electron window. clicking on "Click Me" button in Counter page does not work. In the dev tools console window the following error is shown.
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.
Reacted by Lars, Heartlander, Rami, Gillian Fries and Alyssa
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'
_resolveUrl(e) {
if (0 === e.lastIndexOf("https://", 0) || 0 === e.lastIndexOf("http://", 0))
return e;
if (!Wt.isBrowser)
throw new Error(`Cannot resolve '${e}'.`);
const t = window.document.createElement("a");
return t.href = e,
this._logger.log(Ot.Information, `Normalizing '${e}' to '${t.href}'.`),
t.href
}
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.
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>
Reacted by Elangovan Manickam, Ernie Salazar, Pierre Arnaud, Adam Drewery, Bob, Mikhail Gerassimov, Alexander Zhuravlev, Lars, Heartlander, Nikita Napreenkov and 9 more
Reacted by Trần Tiến Đạt, Rami, Al Rodriguez, Gillian Fries and 天使Ø
Reacted by Rami, Gillian Fries, Edvinas Zizminskas and 天使Ø
Activity
peter-bozovic commentedon 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 commentedon 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 commentedon 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 commentedon Dec 3, 2023
I will test and give the feedback.
I was searching for a workaround also.
rubenmonteiro commentedon 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 commentedon 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
fix: resolve Blazor loading error
datttit commentedon 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 commentedon 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.jswell0549 commentedon Nov 11, 2024
Thanks this helped me too
Add nodeIntegration false in auth window options to avoid a bug with …
FlorianRappl commentedon Oct 31, 2025
Outdated - use
ElectronNET.CoreandElectronNET.Core.AspNet.See Wiki / What's New.