在构建代码并将其部署到Azure时出现此错误。 使用VSCode在本地运行代码时,该代码不会出现在控制台中。 对此问题的任何帮助,我们将不胜感激。
清单文件代码:
{
"name": "",
"icons": [
{
"src": "assets/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
}
],
"theme_color": "#ffffff",
"background_color": "#ffffff",
"display": "standalone"
}
在index.html中引用文件的方式如下
<link rel="manifest" href="assets/manifest.json">
答案 0 :(得分:0)
使用标记中的crossorigin =“ use-credentials”修复了该问题。
<link rel="manifest" crossorigin="use-credentials" href="./assets/manifest.json">
答案 1 :(得分:0)
尝试在name属性中添加名称 记住,它不能为空,不能包含空格,不能包含大写字母。
答案 2 :(得分:0)
crossorigin
属性可以帮助您解决问题。对于大多数其他人而言,这可能并不能解决问题。无论如何。
缺少清单文件可能有多种原因,这导致出现此错误消息。除了缺少将其放置在html文件的根目录中并在html文件的head
中引用之外,最常见的是您在另一个环境中进行构建。
所有这些环境都有自己的配置。其中一些默认情况下可能不会将manifest.json文件包装/打包到本地测试部署包中。
在Angular中,您可以通过在路径"src/manifest.json"
中的angular.json文件:projects/app/root/architect/build/options/assets
中的指令将清单添加到资产中来解决此问题
答案 3 :(得分:0)
我尝试了很多修复,但都没有奏效。经过多次磨牙,我发现 Azure 不会将 .json 用作静态文件。
所以我在 web.config 中添加了以下内容(摘录如下)。
<configuration>
<system.webServer>
...
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
<mimeMap fileExtension=".webmanifest" mimeType="application/json" />
</staticContent>
...
</system.webServer>
</configuration>
SO 上的许多解决方案都提到了此修复程序,但 .webmanifest 文件文件 ext 的第二个 MIME 设置除外。
它只对我有用,包括第二个文件扩展名“.webmanifest”。
答案 4 :(得分:0)
您需要将 MIME 类型添加到您的服务器。扩展 Makefile
mime type .webmanifest
答案 5 :(得分:0)
如果您对其他答案有疑问,可以使用这个:
尝试先删除 mimetype,然后在 web.config 中再次添加
(在 web.config 中添加)
<staticContent>
<remove fileExtension=".json"/>
<mimeMap fileExtension=".json" mimeType="application/json" />
<remove fileExtension=".webmanifest"/>
<mimeMap fileExtension=".webmanifest" mimeType="application/json" />
</staticContent>
答案 6 :(得分:-1)
我今天在Azure上托管Angular 6项目时遇到了同样的错误。
这是我的解决方法:
在我的“ web.config”文件中:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Angular" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
添加以下行:
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
结果:
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
<rewrite>
<rules>
<rule name="Angular" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
对我有用,希望对您也有用! :)