spiderhamer
spiderhamer

Reputation: 53

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.

Upvotes: 5

Views: 2926

Answers (2)

Dirkmal
Dirkmal

Reputation: 76

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.

Upvotes: 6

null
null

Reputation: 21

In your "createWindow" function in your main.ts, do you see this configuration? :

webPreferences: { nodeIntegration: true }

It should be present in your creation of the browser window using the command

new BrowserWindow({})

inside the brackets you would have you window size dimensions and it is also where the webPreferences should go.

The Strict MIME type error is most likely from your Electron build interpreting ES6 Javascript or typescript wrong.

So setting the nodeIntegration to true, should solve the problem

Upvotes: 0

Related Questions