-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
After 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
@kdawg1406 sounds like a server issue to me. What happens if you serve a production build yourself locally? I bet that works. |
@spock123 thank you for your remarks. I'll try this in the morning. |
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> |
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. |
@Drol yes the correct files were being requested by name in the index.html file that the build created. Thank you for the suggestion. |
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! |
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. |
Thanks for the update @kdawg1406. |
Same problem here, and no obvious fix still? Prod build uploaded to Github Pages does not work too. |
@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. |
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/ |
@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 issue is posted on Stack Overflow , but no resolution yet, thanks! |
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'" ? |
@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. |
@kdawg1406 Thank you very much! |
try browerslist |
Same issue when packaging with Electron, seems to be resolved by setting type="text/javascript" instead of type="module". |
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:
|
@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). |
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
|
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".
|
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. |
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 |
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. |
Same issue, It's seems like ng8 issue and not something that can be fixed on the node side |
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. |
+1 |
Still no solution to this problem?? |
Changing the type attribute on the script tags in the compiled index.html file fixes this for me, but adds an additional step to the deployment for Google App Engine (for reference NGINX and apache serve correctly without issue). Prior versions of angular built and deployed to GAE without issue. |
Yes, that may be one of the solution, I prefer
https://stackoverflow.com/a/63207836/14033778 here you don't need any
additional steps.
…On Sat, Aug 1, 2020 at 9:43 PM iabutler ***@***.***> wrote:
Changing the type attribute on the script tags in the compiled index.html
file fixes this for me, but adds an additional step to the deployment for
Google App Engine (for reference NGINX and apache serve correctly without
issue).
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#30835 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMHE6SRNRNDYLJ2WSJAWNFLR6Q5LRANCNFSM4HSYDBKQ>
.
|
It helped to me. |
@Amitesh as noted elsewhere, if you are running into this on Electron this is expected as the For more information about this, see the Electron docs. You can find folks discussing this solution (and an example custom protocol) at electron/electron#12011 (comment) |
If you are using DotNetCore 3.1, make sure app.UseSpaStaticFiles(); is in Startup.cs. |
Thanks @rezonant |
Does anyone have any idea where the Angular 7 to Angular 8 change is where the |
Yes, this resolved my issue for running Angular 8 project into Nginx docker container. |
In my case, I had the same problem publishing an Angular 9 application on an IIS 8 server. The error only occurred on the customer's machine and not on mine. The reason was this: In my machine I published the application indicating in the baseRef that it would be inside a folder myFolder within the Site. In the case of my customer, he did not create the folder within an existing site, but instead created the folder and a new site that points directly to it. The solution in my case was to generate the publish without specifying the baseRef (just ng build --prod). In short, the error is that the server cannot locate the project files according to how it was compiled. |
I am also facing the same issue with my angular app deployed in AKS with nginx container and ingress enabled. |
We have also this problem with Nginx ingress enabled on AKS |
can you share the script which does this? Thanks in advance. |
I struggled with this issue for a whole day and finally, it was some infra issue with Kubernetes. I don't have details at the moment, but when it happens to you, don't think it is just your angular code issue. This can occur from different layers. I'll update this post about what went wrong in K8 once I got the post-mortem from our ci team. |
I've been having this problem for a few days now. (Angular 10) _Package Version@angular-devkit/architect 0.1000.1 No changes to server config. This is what happened:
I got my co-worker to build and push the exact same branch, works fine. Two of the built js files were different:
I tried uninstalling Flutter, Android Studio, Visual Studio 2019, uninstalling and reinstalling nodejs, tried downloading WebStorm and building from, nothing worked. What did work was changing the type="module" in the scripts in the index.html file, but what I am concerned about is why those 2 js files are different from my co-workers build. |
Some servers don't serve the .js files with the correnct headers. This change documents the requirement. Fixes angular#30835
Some servers don't serve the .js files with the correnct headers. This change documents the requirement. Fixes angular#30835
@FCE-tc Something odd is going on here... |
I ended up getting around this by using Actions in Git to build and deploy the Angular app. So I'm guessing this is an issue that is related to Visual Studio and its install files. |
@FCE-tc Since I am working with AWS S3 for hosting, I could directly verify in their console that the mime type is now correct for .js files, which was not the case beforehand. Maybe this helps someone. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
🐞 bug report
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.
🔬 Minimal Reproduction
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.
🔥 Exception or Error
🌍 Your Environment
Angular Version:
The text was updated successfully, but these errors were encountered: