Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Electron Failed to load Module

When I try to load my Angular Project as an Electron app, I get the following error:

Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.**

I used this tutorial to create the application and now I'm trying to add some components. So my code is similar to the one supplied in the tutorial I just added the Homecomponent with ng generate.

https://malcoded.com/posts/angular-desktop-electron/

The solution that was given in the tutorials comment section isn't working for me or maybe I'm doing something wrong.

like image 226
spiderhamer Avatar asked Jun 27 '19 09:06

spiderhamer


1 Answers

I faced the same issue recently and after some research discovered this error is caused by Angular 8 not adding MIME types to Typescript files converted to js. If you ng serve and inspect the page, you'll notice the js scripts have a type of "module", this confuses Electron. There are several workarounds, as discussed in this GitHub issue.

What worked for me was simply changing the "target" property in the "compilerOptions" of tsconfig.json to "es5".

I hope someone finds this useful.

like image 162
Dirkmal Avatar answered Nov 24 '22 00:11

Dirkmal