简体   繁体   English

Manifest.json 意外令牌

[英]Manifest.json Unexpected Token

Hello I pushed a react/express project up to heroku ( https://polar-oasis-57801.herokuapp.com/ ) and received the following errors in the console: Chrome console error messages您好,我将一个 react/express 项目推送到 heroku ( https://polar-oasis-57801.herokuapp.com/ ) 并在控制台中收到以下错误: Chrome 控制台错误消息

I tried looking up this error and it seems that I need to change something in my manifest.json file but I'm not sure.我尝试查找此错误,似乎我需要更改 manifest.json 文件中的某些内容,但我不确定。 Any advice would help.任何建议都会有所帮助。 Here's my manifest file:这是我的清单文件:

{
  "short_name": "React App",
  "name": "Create React App Sample",
  "icons": [
    {
      "src": "favicon.ico",
      "sizes": "64x64 32x32 24x24 16x16",
      "type": "image/x-icon"
    }
  ],
  "start_url": ".",
  "display": "standalone",
  "theme_color": "#000000",
  "background_color": "#ffffff"
}

And also my project on Github: https://github.com/bernar83/cat-cards还有我在 Github 上的项目: https : //github.com/bernar83/cat-cards

This error means that the request to manifest.json does not return a valid JSON response.此错误意味着对manifest.json的请求未返回有效的 JSON 响应。 Probably it returns an HTML, given the fact that it fails because of a starting < .考虑到它由于起始<失败而失败,它可能会返回一个 HTML。

Be sure to link the manifest.json correctly and make sure to preserve its integrity in the deployment process.确保正确链接manifest.json并确保在部署过程中保持其完整性。 Try to navigate to http://yoururl/manifest.json and check the result.尝试导航到http://yoururl/manifest.json并检查结果。

EDIT1: it seems like your link to the manifest is broken. EDIT1:您的清单链接似乎已损坏。 In https://github.com/bernar83/cat-cards/blob/master/client/public/index.html , try replacinghttps://github.com/bernar83/cat-cards/blob/master/client/public/index.html 中,尝试替换

<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />

with

<link rel="manifest" href="manifest.json" />

EDIT2: Just checked your Heroku link and can confirm the error. EDIT2:刚刚检查了您的 Heroku 链接并可以确认错误。 Your page tries to find the manifest.json under the path /cat-cards/manifest.json which is wrong.您的页面尝试在/cat-cards/manifest.json路径下查找manifest.json ,这是错误的。 It should only be manifest.json它应该只是manifest.json

I added this change "/cat-cards/" in my server.js file so now it's app.use("/cat-cards/", express.static("client/build"));我在 server.js 文件中添加了这个更改"/cat-cards/"所以现在它是app.use("/cat-cards/", express.static("client/build")); . . Adding that change and pushing to Heroku made my website work.添加该更改并推送到 Heroku 使我的网站正常工作。 This helped me: https://github.com/facebook/create-react-app/issues/1812#issuecomment-286511320这对我有帮助: https : //github.com/facebook/create-react-app/issues/1812#issuecomment-286511320

I had a similar issue.我有一个类似的问题。 I'll add it since this is the SO post I ended up at while trying to figure it out.我会添加它,因为这是我在试图弄清楚时最终看到的 SO 帖子。 I'd included some generated favicon markup to my "JS not allowed" file.我在我的“JS not allowed”文件中包含了一些生成的图标标记。 My manifest.json is in my src/ directory, so the pasted in markup was referencing a manifest that wasn't in my public root.我的 manifest.json 位于我的 src/ 目录中,因此粘贴在标记中引用了不在我的公共根目录中的清单。 The boilerplate code then returned the "JS not allowed here" EJS HTML as the actual return value for the manifest.json , so the browser saw it as malformed JSON... Not ideal.然后样板代码返回“此处不允许使用 JS”EJS HTML作为 manifest.json 的实际返回值,因此浏览器将其视为格式错误的 JSON... 不理想。

So, if your router is going to return this sort of thing for bad HTTP requests, like Ant Design Pro does, it could be your problem.因此,如果您的路由器要为错误的 HTTP 请求返回此类内容,就像 Ant Design Pro 所做的那样,那可能是您的问题。

yeah I faced this problem and struggled a lot with it then I follow This helped me: https://github.com/facebook/create-react-app/issues/1812#issuecomment-286511320 link.是的,我遇到了这个问题并为此苦苦挣扎,然后我遵循这对我有帮助: https : //github.com/facebook/create-react-app/issues/1812#issuecomment-286511320链接。 it definitely works.它绝对有效。 I am thankful to the person who shares this link.我感谢分享此链接的人。

I had the same issue I solve it by:我遇到了同样的问题,我通过以下方式解决它:

  1. Go into package.json file in your react app.进入 react 应用程序中的 package.json 文件。

  2. You will see the homepage attribute at the top, remove it either copy that URL.您将在顶部看到主页属性,将其删除或复制该 URL。

  • If you remove it then again create build and use that build in your express.static('./build') .如果您删除它,则再次创建构建并在您的express.static('./build')使用该构建。

  • If you copy it then use that url in your app.use("that copied url" , express.static('./build')) in your express server file.如果您复制它,则在您的快速服务器文件中的app.use("that copied url" , express.static('./build'))中使用该网址。

Check the index.html inside build and inside your public folder.检查内部构建和公共文件夹中的 index.html。 I had the same issues and just found that issue was with Html nothing else.我遇到了同样的问题,只是发现问题与 Html 无关。

Thanks Binod Singh感谢比诺·辛格

Ran into this issue today.今天遇到这个问题。 The issue for my team was that in the server.js file, the app.use(routes) line was above the the static assets app.use(express.static("client/build"))我团队的问题是在 server.js 文件中, app.use(routes)行位于静态资产app.use(express.static("client/build"))之上

Moving it below allowed the site to deploy to heroku appropriately.将它移到下方允许站点适当地部署到 heroku。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM