Blazor Web App (.net8) - error: Cannot resolve '_blazor' when started by - electronize start #921

Closed
opened 2026-01-29 16:51:59 +00:00 by claunia · 10 comments
Owner

Originally created by @Elangovan4ever on GitHub (Nov 15, 2023).

  • Version:
    .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

  • 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'.".

Test Project on GitHub: https://github.com/elandev4ever/SimpleBlazorWebApp

Steps to Reproduce:

  1. 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".
  2. 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.
  3. 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]
  4. In Windows Command prompt navigate to app folder, and run the following commands:
    dotnet tool install ElectronNET.CLI -g
    electronize init
    electronize start
  5. 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.

Originally created by @Elangovan4ever on GitHub (Nov 15, 2023). * **Version**: .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 * **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'.". Test Project on GitHub: https://github.com/elandev4ever/SimpleBlazorWebApp Steps to Reproduce: 1. 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". 2. 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. 3. 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] 5. In Windows Command prompt navigate to app folder, and run the following commands: dotnet tool install ElectronNET.CLI -g electronize init electronize start 6. 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.
claunia added the bug label 2026-01-29 16:51:59 +00:00
Author
Owner

@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

@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
Author
Owner

@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'

_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.

I don't know if this is related

Code in aspnetcore repo

this is the same condition

@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' ``` _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. I don't know if this is related [Code in aspnetcore repo](https://github.com/dotnet/aspnetcore/blob/82cb091f6052b7fe063b72229d1fc22d84d275c3/src/SignalR/clients/ts/signalr/src/Utils.ts#L39) this is the same condition
Author
Owner

@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>

@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>`
Author
Owner

@rubenmonteiro 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>

I will test and give the feedback.
I was searching for a workaround also.

@rubenmonteiro 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>` I will test and give the feedback. I was searching for a workaround also.
Author
Owner

@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

@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
Author
Owner

@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

@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
Author
Owner

@datttit commented on GitHub (Sep 23, 2024):

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>

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!

@datttit commented on GitHub (Sep 23, 2024): > 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>` 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!
Author
Owner

@tonsnoei commented on GitHub (Nov 2, 2024):

Great work! Thanks! Just some additional info, the code is located in _Host.cshtml and now it is called blazor.server.js instead of blazor.web.js

@tonsnoei commented on GitHub (Nov 2, 2024): Great work! Thanks! Just some additional info, the code is located in `_Host.cshtml` and now it is called `blazor.server.js` instead of `blazor.web.js`
Author
Owner

@well0549 commented on GitHub (Nov 11, 2024):

Thanks this helped me too

@well0549 commented on GitHub (Nov 11, 2024): Thanks this helped me too
Author
Owner

@FlorianRappl commented on GitHub (Oct 31, 2025):

Outdated - use ElectronNET.Core and ElectronNET.Core.AspNet.

See Wiki / What's New.

@FlorianRappl commented on GitHub (Oct 31, 2025): Outdated - use `ElectronNET.Core` and `ElectronNET.Core.AspNet`. See [Wiki / What's New](https://github.com/ElectronNET/Electron.NET/wiki/What's-New).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#921