【问题标题】:jsreact - GET http://localhost:8080/manifest.json 404 (Not Found)jsreact - 获取 http://localhost:8080/manifest.json 404(未找到)
【发布时间】:2018-07-04 09:46:02
【问题描述】:

我正在尝试通过添加 manifest.json 来使我现有的 React 应用程序渐进式。

但是,当我收到上述错误消息和 Cannot GET /manifest.json 时,我的应用程序似乎无法找到我的 manifest.json 文件查看开发人员工具的网络选项卡。这很奇怪,因为我的 manifest.json 位于我的应用程序的根目录,正是错误表明它找不到文件的位置。

我尝试了几种方法,例如在每个目录中放置一个 manifest.json 文件,或者在我的 webpack 配置中引入一个 json-loader,但没有任何效果。

我在哪里引用清单

<!DOCTYPE html>
<html lang="de">
  <head>
    <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="manifest" href="/manifest.json" >
  </head>
  <body>
    <div id="root" class="body"></div>
  </body>
</html>

此外,我正在使用 webpack-manifest-plugin,它会在我的构建目录中创建一个 asset-manifest.json 文件来映射我的索引文件。

webpack.config

//...
const ManifestPlugin = require("webpack-manifest-plugin")
module.exports = {
    plugins: [
        new ManifestPlugin({
            fileName: "asset-manifest.json"
        })
        //...

创建asset-manifest.json

{
  "index.js": "index.bundle.js",
  "index.html": "index.html"
}

希望你能帮到我

【问题讨论】:

  • 实际文件是asset-manifest.json,但你试图指向manifest.json??我错了吗?
  • 您在 webpack 配置中将 fileName 更改为 asset-manifest.json,但您在文档中链接到 /manifest.json。您可以在文档中尝试/asset-manifest.json 吗?
  • asset-manifest.json 由插件生成,其中包含所有源文件名到其相应输出文件 (npmjs.com/package/webpack-manifest-plugin) 的映射。它不是我要引用的 manifest.json 文件。

标签: javascript reactjs webpack http-status-code-404 manifest.json


【解决方案1】:

问题不仅在于 manifest.json,还在于所有 json 文件。正如这里所说:https://stackoverflow.com/a/29633038/3231884,您需要根据以下示例设置 web.config:

<?xml version="1.0"?>
<configuration>
    <system.webServer>
        <staticContent>
        <remove fileExtension=".json" />
        <mimeMap fileExtension=".json" mimeType="application/json" />
      </staticContent>
    </system.webServer>
</configuration> 

之后,您应该按照以下步骤将“npm run build”复制到构建文件夹(感谢 Liviu Costea): https://medium.com/hackernoon/adding-web-config-to-react-projects-3eb762dbe01f

【讨论】:

    【解决方案2】:

    更改扩展清单 从 ma​​nifest.jsonmanifest.txt

    【讨论】:

      【解决方案3】:

      应该是manifest.json文件的问题。 请显示manifest.json文件的内容。

      试试这个,在manifest.json name 属性应为小写字母且不包含空格。

      【讨论】:

        猜你喜欢
        • 2021-01-26
        • 2020-10-14
        • 2019-05-08
        • 2021-06-18
        • 1970-01-01
        • 2013-06-03
        • 2019-06-13
        • 2020-12-29
        • 1970-01-01
        相关资源
        最近更新 更多