3

I built my application running ng build --configuration=production and uploaded it (manually via FTP) to a server (I tried two different ones). Accessing the root like myurl.com works fine, but whenever I want to directly access a subpage, for example, myurl.com/subpage the page is blank and I get the following error: Loading module from “https://myurl.com/runtime-es2015.js” was blocked because of a disallowed MIME type (“text/html”). Same error for also for polyfills-es2015.js, main-es2015.js

If I access the root and navigate to the subpage everything works fine.

Until now I tried to:

  • set <base href="."> in index.html

  • set "target": "es5" in tsconfig.json

  • manually change the type of the scripts from type="module" to type="text/javascript" like here: <script src="runtime-es2015.js" type="text/javascript">

Angular CLI & Angular Version 8.1

Typescript version 3.4.5

Webpack version 4.35.2

On the server, I also have a .htaccess file which was needed, as otherwise accessing myurl.com/subpage resulted in a 404

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>

I would be really thankful, if somebody could help me.

Edit Accessing the "subpage" during ng serve works fine!

Edit2 When inspecting the Network tab in the development console on the browser, the GET requests for the .js files work fine, but the type is wrong (html). If I load the root page (myurl.com) the mime-type is correct.

kWin
  • 31
  • 1
  • 5
  • I had the same issue, I have mentioned how I resolved it. There is a similar post. Please refer this post https://stackoverflow.com/a/62226117/12080473 sometimes the error message in the console misleads the actual cause of the issue. – Karthik Jun 06 '20 at 01:10

1 Answers1

5

I had a similar problem with an Angular app I deployed to https://host.my/app. As mentioned in other SO answer changing the

<base href="/">

to

<base href="./">

solved it for me. Just setting it to <base href="."> did not.

HTH

M-x
  • 658
  • 7
  • 13