I would like to serve an Angular 8 app with a simple Nginx server. Unfortunately, when I try to serve the app I receive the following error in Chrome:
Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec.
I found several solutions (this and that for instance) suggesting I should manually configure all script
tags and add type="javascript"
. However, in my case I cannot do this because my app contains Web Components that can only be loaded when the script type attribute is type="module"
.
My Nginx configuration looks like this:
events { worker_connections 1024; }
http
{
sendfile on;
server {
root /usr/share/nginx/html/app;
listen 9020;
server_name localhost;
location / {
index index.html index.htm;
}
location ~ \.css {
add_header Content-Type text/css;
}
location ~ \.js {
add_header Content-Type application/javascript;
}
}
}
Do you know how I can configure either Angular or Nginx to serve javascript files (included by script
tags in the index.html
) which are of type "module"?
Thank you in advance.