首页 > 解决方案 > 在我的反应 js 项目中运行 npm start 时出现白屏

问题描述

那么 <strictmode 会导致这个问题吗???2我在尝试运行 npm start 时出现白屏。npm start 有效,但我在 http://localhost:3000/ 上出现白屏。我试图将 {"homepage": ".",} 添加到我的 index.html 文件中,但我仍然收到相同的错误?你能告诉我我在哪里做错了吗?我也尝试通过谷歌控制台调试它,但它什么也没显示。3

index.html file:
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="stylesheet" href=" https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="https://unpkg.com/purecss@2.0.3/build/grids-responsive-min.css">
    <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>

**package.json file** 

    {
      "name": "chatapp",
      "version": "0.1.0",
      "homepage": ".",
      "private": true,
      "dependencies": {
        "@testing-library/jest-dom": "^4.2.4",
        "@testing-library/react": "^9.3.2",
        "@testing-library/user-event": "^7.1.2",
        "firebase": "^7.19.1",
        "font-awesome": "^4.7.0",
        
        "react": "^16.13.1",
        "react-dom": "^16.13.1",
        "react-loading": "^2.0.3",
        "react-router-dom": "^5.2.0",
        "react-scripts": "3.4.3",
        "react-toastify": "^6.0.8"
      },
      "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test",
        
        "eject": "react-scripts eject"
      },
      "eslintConfig": {
        "extends": "react-app"
      },
      "browserslist": {
        "production": [
          ">0.2%",
          "not dead",
          "not op_mini all"
        ],
        "development": [
             "last 1 chrome version",
             "last 1 firefox version",
             "last 1 safari version"
        ]
      }
    }

标签: javascripthtmlreactjsfrontend

解决方案


这将修复错误。

命令

npm install chalk

推荐阅读