Angular 8 ng-build throwing MIME error with cordova

Nidhin Joseph picture Nidhin Joseph · Jun 15, 2019 · Viewed 12k times · Source

While executing ng build --prod --base-href ./ for building my cordova app, the final output throws an error as below.

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 did end up fixing this by changing type module to text/javascript

src="runtime-es2015.858f8dd898b75fe86926.js" type="module">

src="runtime-es2015.858f8dd898b75fe86926.js" type="text/javascript">

Is there something that can be done within angular.json file to fix or am I missing out something here?

Answer

englishPete picture englishPete · Sep 1, 2019

I had the same issue.

  1. Created a new project.
  2. Built a production version

      "build-production": "ng build --configuration=production --extract-css=false --prod --aot"
    
  3. Deployed to NGINX

  4. White page with no content between tags in Chrome Element inspector

Fix

Update tsconfig.json

        "target": "es5",

Then rebuild the application and deploy again.

This solution worked for me, I now have content in my deployed app.

Hope it helps somebody