Search code examples
blazorblazor-webassembly

Loading module from “.../_framework/dotnet.js” was blocked because of a disallowed MIME type (“text/html”)


My project runs fine on local host, but when I publish a Blazor WebAssembly app to Azure I get:

Loading module from “https://aistorybuilderstest.azurewebsites.net/_framework/dotnet.js” was blocked because of a disallowed MIME type (“text/html”).
aistorybuilderstest.azurewebsites.net
Loading failed for the module with source “https://aistorybuilderstest.azurewebsites.net/_framework/dotnet.js”. aistorybuilderstest.azurewebsites.net:73:52
Uncaught (in promise) Error: Failed to start platform. Reason: TypeError: error loading dynamically imported module: https://aistorybuilderstest.azurewebsites.net/_framework/dotnet.js
    mn https://aistorybuilderstest.azurewebsites.net/_framework/blazor.webassembly.js:1

This project ran fine on Azure for months and I only made a small change to a .razor file. I had also upgraded the Nuget packages but I rolled back all those changes and it still wont work.

I created a new Blazor WebAssembly project and published to Azure and it also wont work.

It just shows:

enter image description here

I restored a back-up of a project that works and compared the files and I see that in the project that does not work the Dotnet.js files are missing.

enter image description here

Why are they missing? I have no idea :( I am running the latest Visual Studio Version 17.9.6

If I run the project locally the dotnet.js file is there and loads:

enter image description here


Solution

  • I've pinpointed the issue to the Visual Studio publishing wizard failing to push all files, regardless of my efforts. Subsequently, I established a new Azure Web App under a fresh subscription, which resolved the issue. Thus, the publish destination seems to be the culprit, though the reason remains unclear. Nevertheless, I've devised a workaround by publishing to an alternative Azure WebApp.

    ** Update: The discrepancy between the sites where publishing is successful versus those where it isn't lies in the age of the Azure App Services; newer ones function correctly, while the older ones do not, despite previously operating without issue.