Hello i get this errors in console browser in my angular 8 app, i see the browser windows blank and i get this error
Uncaught SyntaxError: Unexpected token '<'
i try run my ng build
ng build --base-href / --aot --prod
ng build --base-href /my_app/ --aot --prod
ng build --prod
ng build --aot --prod --output-hashing none
nothing works...
my apache config file
<VirtualHost *:80>
DocumentRoot "/var/www/html/MrpProy/my_app/dist/my_app/"
ServerName mydomain.com
<Directory /var/www/html/MrpProy/my_app/dist/my_app/>
RewriteEngine on
# Rewrite everything else to index.html to allow HTML5 state links
RewriteRule ^ index.html [L]
</Directory>
</VirtualHost>
how this solve?
As @MikeOne stated in comments earlier...
You’re probably returning the
index.htmlon the javascript requests as well..
because of your Apache config...
# Rewrite everything else to index.html to allow HTML5 state links RewriteRule ^ index.html [L]
This literally rewrites everything (not just "everything else") to index.html. So, when requesting anything.js, the server is responding with index.html. So, yes, the browser is trying to parse index.html as JavaScript.
Your Apache config should be something like this instead, in order to prevent requests for static resources being rewritten to index.html:
RewriteEngine on
# Rewrite everything that does not look-like a file to index.html
RewriteRule !\.\w{2,4}$ index.html [L]
Or, slightly less efficient (but possibly more flexible):
# Rewrite everything that is not a file to index.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [L]