简体   繁体   English

部署 Angular 项目错误类型 MIME (text/html)

[英]Deployment Angular Project error type MIME (text/html)

I try to deploy an Angular/CLI 6.12.0 project.我尝试部署一个 Angular/CLI 6.12.0 项目。

When I put "dist" folder content on a server, there is a console error "type MIME".当我将“dist”文件夹内容放在服务器上时,出现控制台错误“type MIME”。

Le chargement du module à l’adresse « http://www.sylvainallain.fr/polyfills-es2015.fd917e7c3ed57f282ee5.js » a été bloqué en raison d’un type MIME interdit (« text/html »).
Le chargement du module à l’adresse « http://www.sylvainallain.fr/main-es2015.2fcd6517edb1de962f8a.js » a été bloqué en raison d’un type MIME interdit (« text/html »).
Le chargement du module à l’adresse « http://www.sylvainallain.fr/runtime-es2015.24b02acc1f369d9b9f37.js » a été bloqué en raison d’un type MIME interdit (« text/html »).

https://imgur.com/fQKnWAg.jpg https://imgur.com/fQKnWAg.jpg

This in French for me ^^.这对我来说是法语^^。 You can see it in console here http://biblio.sylvainallain.fr您可以在控制台中看到它http://biblio.sylvainallain.fr

It's a simply application like a library.它是一个像图书馆一样的简单应用程序。 Back-end (logs and data) is manage with Firebase.后端(日志和数据)由 Firebase 管理。

In local, all is OK.在本地,一切正常。

I make the build with "ng build --prod", it create a "dist" folder.我使用“ng build --prod”进行构建,它创建了一个“dist”文件夹。

My index.html after prod:产品后我的 index.html:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Bibliothèque Angular</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="styles.735ba4029395bfd97371.css"></head>
<body>
  <app-root></app-root>
    <script src="polyfills-es5.f9fad3ad3c84e6dbdd72.js" nomodule defer></script>
    <script src="polyfills-es2015.fd917e7c3ed57f282ee5.js" type="module"></script>
    <script src="runtime-es2015.24b02acc1f369d9b9f37.js" type="module"></script>
    <script src="main-es2015.2fcd6517edb1de962f8a.js" type="module"></script>
    <script src="runtime-es5.24b02acc1f369d9b9f37.js" nomodule defer></script>
    <script src="main-es5.2fcd6517edb1de962f8a.js" nomodule defer></script></body>
</html>

I find this GitHub post: https://github.com/angular/angular-cli/issues/10325 .This is the same issue, I try some solutions but nothing work.我发现这个 GitHub 帖子: https://github.com/angular/angular-cli/issues/10325 。这是同样的问题,我尝试了一些解决方案,但没有任何效果。

The issue is only with es2015.*.js files.问题仅与es2015.*.js文件有关。 So I think there is an issue with type="module" which is not recognize like a Javascript file.所以我认为type="module"存在一个问题,它不像 Javascript 文件那样被识别。 I don't understand why Angular don't manage it.我不明白为什么 Angular 不管理它。

Edit 25 October: 10 月 25 日编辑

  • try to replace type="module" with type="application/javascript" .尝试将type="module"替换为type="application/javascript" Don't work.不要工作。 Source 资源

  • try to update Angular/CLI & Angular/core with ng update @angular/cli @angular/core --allow-dirty and ng build --prod again.尝试使用ng update @angular/cli @angular/core --allow-dirtyng build --prod再次更新 Angular/CLI 和 Angular/core。 Don't work不工作

  • try to host it with Firebase.尝试使用 Firebase 托管它。 Same issue: https://bibliang.firebaseapp.com/同样的问题: https://bibliang.firebaseapp.com/

Thanks for help: :)感谢帮助: :)

This is because of dist folder in your project workspace.这是因为项目工作区中的 dist 文件夹。 There are two solutions that worked for me:有两种解决方案对我有用:

Sol 1. In your dist folder there may a folder named as your project name move all the files of that folder to the dist folder and then change the dir location to the dist/index.html in server.js file. Sol 1. 在您的 dist 文件夹中,可能有一个名为您项目名称的文件夹将该文件夹的所有文件移动到 dist 文件夹,然后将 dir 位置更改为 server.js 文件中的dist/index.html

Move all files from dist/you_project_name to dist/将所有文件从dist/you_project_name移动到dist/

Then change the dir location in server.js file 'dist/you_project_name' to 'dist/'然后将 server.js 文件 'dist/you_project_name' 中的 dir 位置更改为 'dist/'

Sol 2. You can change the src attribute of all error causing tags in index.html file, like:: Sol 2. 您可以更改 index.html 文件中所有导致错误的标签的 src 属性,例如:

<script src="runtime-es2015.js" type="module">

changed to变成

<script src="folder_name_inside_the_dist_dir/runtime-es2015.js" type="module">
 <script src="polyfills-es2015.fd917e7c3ed57f282ee5.js" type="module"></script>
    <script src="runtime-es2015.24b02acc1f369d9b9f37.js" type="module"></script>
    <script src="main-es2015.2fcd6517edb1de962f8a.js" type="module"></script>

keep all above file in another folder and give path here like

<script src="../../js/polyfills-es2015.fd917e7c3ed57f282ee5.js" type="text/javascript"></script> 

it will work它会起作用的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MIME 类型 (&#39;text/html&#39;) 错误 - MIME type ('text/html') Error ExpressJS 错误:MIME 类型('text/html')不是受支持的样式表 MIME 类型 - ExpressJS error: MIME type ('text/html') is not a supported stylesheet MIME type 应用 css 样式时出现角度错误:拒绝从“路径”应用样式,因为其 MIME 类型(“文本/html”)不是受支持的样式表 MIME 类型 - Angular error when applying css style: Refused to apply style from 'path' because its MIME type ('text/html') is not a supported stylesheet MIME type 不支持MIME类型(&#39;text / html&#39;) - MIME type ('text/html') is not a supported “php 脚本已加载,即使其 MIME 类型(“text/html”)不是有效的 JavaScript MIME 类型”错误 - “The php script was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type” error Service Worker 注册错误:不支持的 MIME 类型('text/html') - Service Worker registration error: Unsupported MIME type ('text/html') Django CSS/JS MIME 类型(“text/html”)不匹配错误 - Django CSS/JS MIME type (“text/html”) mismatch Error 注册时的 ServiceWorker MIME 类型错误 (&#39;text/html&#39;) (React) - ServiceWorker MIME Type Error ('text/html') on register (React) 模拟服务器错误 - 脚本具有不受支持的 MIME 类型 ('text/html') - Mock server error - The script has an unsupported MIME type ('text/html') NodeJS,MIME 类型 (&#39;text/html&#39;) 不是受支持的样式表 MIME 类型 - NodeJS, MIME type ('text/html') is not a supported stylesheet MIME type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM