SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON

回答 2 浏览 3万 2022-08-15

这是一个PERN应用程序。我不记得曾经遇到过这个错误,而且我在谷歌搜索时也没有发现任何记录。

我在index.html中没有看到任何问题。

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      name="description"
      content="Web site created using create-react-app"
    />
    <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
    <!--
      manifest.json provides metadata used when your web app is installed on a
      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
    -->
    <!-- <link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> -->
    <!--
      Notice the use of %PUBLIC_URL% in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    -->
    <title>React App</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    -->
  </body>
</html>

是否知道它是从哪里来的?我一启动应用程序就会得到它。

Paulprg19 提问于2022-08-15
看起来你是想把一个HTML文档当作JSON来解析。这是不可能的,因为HTML不是JSON......如果没有关于你的应用程序的进一步信息,就不可能知道它为什么要这样做。Jesper 2022-08-15
HTML的确是无效的JSON。在你的某个地方有期待JSON而得到HTML的代码。检查它在哪里,结果是什么,这也可能给你一个线索,什么是错的。例如,你可能得到一个有错误的HTML页面。VLAZ 2022-08-15
你想通了吗--我也在努力解决同样的问题。Mel 2022-09-21
2 个回答
#1楼
得票数 3

所以我在安装npm gh-pages的时候也遇到了这个错误。我的解决办法是删除package.json中的Homepage链接,然后就成功了。

Burden8 提问于2022-09-09
您的答案可以通过额外的支持信息得到改进。请编辑以添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。您可以在帮助中心找到更多关于如何写好答案的信息。Community 2022-09-13
#2楼
得票数 0

我是个新手,但我发现如果我在package.json中添加一个代理(客户端,而不是服务器端),它就会起作用!在package.json中是这样的:"proxy": "; .在package.json中看起来是这样的(放在我的依赖项之上):"proxy": "http://localhost:3001"。我相信这是因为客户端无法读取它,而代理告诉它把它传递给可以读取它的服务器端。

Tbro4 提问于2022-09-25
标签