Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upAfter upgrading to Angular 8, production builds can't load: 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. #30835
Comments
This comment has been minimized.
This comment has been minimized.
spock123
commented
Jun 4, 2019
|
@kdawg1406 sounds like a server issue to me. What happens if you serve a production build yourself locally? I bet that works. |
This comment has been minimized.
This comment has been minimized.
|
@spock123 thank you for your remarks. I'll try this in the morning. |
This comment has been minimized.
This comment has been minimized.
Drol
commented
Jun 4, 2019
|
Check that you are trying to load correct filenames. You are simply getting a 404 from backend and the browser cant load the 404 page as JS as a <script> |
This comment has been minimized.
This comment has been minimized.
|
Hello, we reviewed this issue and determined that it doesn't fall into the bug report or feature request category. This issue tracker is not suitable for support requests, please repost your issue on StackOverflow using tag If you are wondering why we don't resolve support issues via the issue tracker, please check out this explanation. |
alan-agius4
closed this
Jun 4, 2019
This comment has been minimized.
This comment has been minimized.
|
@Drol yes the correct files were being requested by name in the index.html file that the build created. Thank you for the suggestion. |
This comment has been minimized.
This comment has been minimized.
Aurora7Sys
commented
Jun 7, 2019
|
I am not so sure this should be closed or sent off to Stack Overflow just yet. Version 8 apps Do work fine on a "real" web server though. Thanks! |
This comment has been minimized.
This comment has been minimized.
|
I found the source of the problem. Angular 8 removed -- type="text/javascript" from the script tags in index.html. Angular 7 had them which is why it worked with Azure Storage. We also discovered that the Azure portal manual upload did not add the MIME metadata to .js files that were uploaded. So... when I manually uploaded my Angular 8 site, it produced the above errors. I started using Visual Studio Code to publish my Angular 8 apps to Azure Storage and it's working because the publish extension adds the correct MIME metadata to the files. Microsoft will look into correcting the Azure portal manual upload to add the MIME metadata so this can't happen on their server. |
This comment has been minimized.
This comment has been minimized.
Aurora7Sys
commented
Jun 7, 2019
|
Thanks for the update @kdawg1406. |
This comment has been minimized.
This comment has been minimized.
lion9
commented
Jun 15, 2019
•
|
Same problem here, and no obvious fix still? Prod build uploaded to Github Pages does not work too. |
This comment has been minimized.
This comment has been minimized.
|
@lion9 does my above solution not work for you? How are you publishing your app to the server? I used VS Code and it solved my problem. |
This comment has been minimized.
This comment has been minimized.
lion9
commented
Jun 15, 2019
I tried to upload it to Github Pages, no luck. It seems that it does not matter, which tool I am using - Webstorm or VS Code - it won't work :-( See here - https://lion9.github.io/test/ |
This comment has been minimized.
This comment has been minimized.
|
@lion9 understand. Full disclosure, my solution worked for me because the VS Code Extension that performs the upload to the Azure Blob Storage applied the correct metadata to the .js files. Angular 8 does publish the .js files differently. If you compare an Angular 7 index.html with the Angular 8 index.html the scripts at the bottom of the file are different. Angular 7 .js files have the type="text/javascript" where the Angular 8 index.html script files do not add this. Angular 7 I believe this is the root of the problem, Recommend contacting GitHub and ask them how you can apply the required metadata to the files. Maybe you can try and add the type="text/javascript" to the script tags that don't have a type attribute? If I remember correctly half of the files have the attribute, the others don't. Best regards, Karl |
This comment has been minimized.
This comment has been minimized.
nj-coder
commented
Jul 2, 2019
|
This issue is posted on Stack Overflow , but no resolution yet, thanks! |
This comment has been minimized.
This comment has been minimized.
Erayus
commented
Jul 3, 2019
|
I got the same problem when I host the files on AWS S3. The problem is from the "type='module'", I had to manually change it into "type='text/javascript'" to make it work again. Why "type='module'" in Angular 8, I'm wondering? What is the benefit of it over "type='text/javascript'" ? |
This comment has been minimized.
This comment has been minimized.
|
@Erayus I think it has something to do with getting a modern browser to load the file instead of the other version of the file. I would reach out to the Angular team, you may be causing a problem. The server metadata needs to be applied to the files, and they will load correctly. I do think Angular needs much better docs and testing to explain to developers how to deploy Angular 8 apps. |
This comment has been minimized.
This comment has been minimized.
Erayus
commented
Jul 4, 2019
|
@kdawg1406 Thank you very much! |
This comment has been minimized.
This comment has been minimized.
hwangzhiming
commented
Jul 8, 2019
|
try browerslist |
This comment has been minimized.
This comment has been minimized.
mxmlbernard
commented
Jul 8, 2019
|
Same issue when packaging with Electron, seems to be resolved by setting type="text/javascript" instead of type="module". |
This comment has been minimized.
This comment has been minimized.
btey
commented
Jul 12, 2019
|
You must change the property "target" in the file "tsconfig.json" to "es5". Read this blog entry, "Differential Loading by Default": This property chooses between modern or legacy JavaScript based on the browser capabilities:
|
This comment has been minimized.
This comment has been minimized.
zanate4019
commented
Jul 16, 2019
|
@btey I don't see anything in the link you provided that suggested target should be es5. Instead the example there shows es2015 (which is es6). |
This comment has been minimized.
This comment has been minimized.
danielgadz
commented
Jul 18, 2019
•
|
I solved it by creating a task in gulp, I share the steps:
note: In the main electron file, make sure you go to the dist folder of your index.html file
|
This comment has been minimized.
This comment has been minimized.
aripp
commented
Jul 23, 2019
•
|
That is a webserver related problem. Angular 7 did include a MIME type in the tags in index.html: Angular 8 does not include a MIME type in <script> tags in index.html:
It's there fore up to the webserver what MIME type is returned when the browser does retrieve the .js file. The solution was to add a .htaccess file into the root directory of the app on the apache webserver to force the server to deliver .js files as MIME type "text/javascript".
|
This comment has been minimized.
This comment has been minimized.
rcketscientist
commented
Jul 24, 2019
•
|
Why is this closed? This is a regression. ng7 created a proper index.html. At least in some situations, ng8 does not. I have not seen a single "solution" that was not a work-around for an ng8 flaw and unrelated to the consumer's code. ng8 should not be creating ambiguous script tags. |
This comment has been minimized.
This comment has been minimized.
MeltedPixel
commented
Jul 27, 2019
•
|
You should be defining your output browser support inside the browserslist file. In this case for the lack of support in modern browsers you should be adding something like:
Adding this inside your browserslist should add support for chrome and chromium based applications. For additional information you can see this github repo. It has a list of other options for inside the browserslist https://github.com/browserslist/browserslist |
This comment has been minimized.
This comment has been minimized.
rcketscientist
commented
Jul 27, 2019
|
Tried that one off SO, no luck. I'll give it a second shot on Monday since this is the second time I've seen it. |
This comment has been minimized.
This comment has been minimized.
itaiRoded2
commented
Aug 6, 2019
|
Same issue, It's seems like ng8 issue and not something that can be fixed on the node side |
This comment has been minimized.
This comment has been minimized.
|
While this only treats the symptom, you can opt out of differential loading to buy you some time to deal with the problem. We use ADO build pipelines to drop files into blob storage running static website and fronted with a CDN, so I may be looking at just running a custom post-copy PS script again like in the earlier days to apply correct mime types. |
This comment has been minimized.
This comment has been minimized.
jrosseel
commented
Aug 8, 2019
|
+1 |
This comment has been minimized.
This comment has been minimized.
keelerjr12
commented
Aug 18, 2019
|
Still no solution to this problem?? |
This comment has been minimized.
This comment has been minimized.
Wolfleader101
commented
Aug 20, 2019
the easy solution
|
This comment has been minimized.
This comment has been minimized.
adamdport
commented
Aug 29, 2019
|
This issue affects anyone using Cordova, as Cordova ultimately serves up files via the Does anyone know if there's any support for the |
This comment has been minimized.
This comment has been minimized.
Arno-v
commented
Sep 1, 2019
|
I use a c++ webserver derived from https://github.com/eidheim/Simple-Web-Server . You can easily create a fast c++ REST server with this, which will serve your angular client. When you request a file it just sends the file. No processing. So if there is no MIME metadata in the file, it will not add it. I don't understand why this issue is closed. Adding the MIME metadata seems simple enough. And if it is inconvenient there should be an option. |
This comment has been minimized.
This comment has been minimized.
peter-snr
commented
Sep 4, 2019
•
|
NGINX configuration was failing even with mime types loaded from /etc/nginx/mime.types. Eventually after some digging, removing one option at a time, I managed to trace the option that was causing the MIME types errors I was getting in the console. Commented it out and viola content was displayed fine.
Hope it helps someone |
This comment has been minimized.
This comment has been minimized.
letanloc1998
commented
Sep 6, 2019
|
I have same problem, does anyone help me, please, thank you very much |
This comment has been minimized.
This comment has been minimized.
wkande
commented
Sep 9, 2019
|
btey had the fix for building with electron. Change the target in tsconfig.json to es5. Thanks btey |
kdawg1406 commentedJun 4, 2019
•
edited
Affected Package Angular 8
Is this a regression? YES
Description
My production distribution is being served from Azure Blob Storage static site. Is it possible that serving from the static site is causing this error?
This issue happens in Chrome but not Edge.
After upgrading to Angular 8, production builds can't load. Browser console error: 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.
Upgrade an Angular 7 app to Angular 8. Do production build, deploy the production build to Azure Blob storage static web site and attempt to open it.
Angular Version: