【问题标题】:trying to use npm start after creating react app returns error创建反应应用程序后尝试使用 npm start 返回错误
【发布时间】:2020-03-02 21:55:37
【问题描述】:

每当我创建一个反应应用程序并尝试启动它时,我都会收到此错误

There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.

The react-scripts package provided by Create React App requires a dependency:

  "webpack": "4.41.5"

Don't try to install it manually: your package manager does it automatically.
However, a different version of webpack was detected higher up in the tree:

  C:\Users\david\node_modules\webpack (version: 4.41.0)

Manually installing incompatible versions is known to cause hard-to-debug issues.

If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to a(n) .env file in your project.
That will permanently disable this message but you might encounter other issues.

我当前的解决方案是将SKIP_PREFLIGHT_CHECK=true 添加到 .env 文件中,但我想普遍解决此问题,因此我不必为我创建的每个 react 应用程序都这样做。

该错误比我发布的要长,它提供了有关如何修复该特定反应应用程序的建议,但没有一个解决方案有效

这是 package.json

{
  "name": "dev-chat",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.4.1",
    "@testing-library/user-event": "^7.2.1",
    "react": "^16.13.0",
    "react-dom": "^16.13.0",
    "react-scripts": "3.4.0"
  },
  "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"
    ]
  }
}

【问题讨论】:

  • 我会尝试全局安装。 npm install -g webpack@4.41.5
  • 请提供您的package.json文件。
  • @stackoverflow-newbie 错误比我发布的要长,它提供了有关如何修复该特定反应应用程序的建议,但没有一个解决方案有效
  • 卸载全球版本。
  • @crashmstr 你能详细说明一下吗?

标签: reactjs npm webpack


【解决方案1】:

我以前在我的一个项目中看到过这种情况,这个错误有时意味着你正在另一个 react 应用程序中安装一个 react 应用程序(具有不同的 webpack 版本)

因为我看到您的 node_modules 安装路径位于系统根目录的 users 文件夹中。您可能在无意的目录中创建了 react 应用程序。

删除您在 C:\Users\david 中创建的 react 应用程序,然后将其重新安装到另一个目录,如 C:\Users\david\desktop,方法是运行如下命令:npx create-react-app [YOUR PROJECT NAME](对于项目名称,请删除方括号)。

【讨论】:

    猜你喜欢
    • 2018-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-30
    相关资源
    最近更新 更多