如何使用react-create-app中的JEST修复错误

时间:2019-09-14 15:59:55

标签: reactjs jestjs babel

我在启动从git克隆的项目时遇到了一个大问题。 我尝试写“ npm i”,以安装所有packejest,然后写npm start,但是我看到错误。

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

  "jest": "24.7.1"

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

  /Users/nazarromanchuk/node_modules/jest (version: 24.9.0) 

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

我知道再删除一次node_modules,package-lock.json和白色“ npm i”-同样的错误

我的package.json外观:

{
  "name": "interview-question",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "react-scripts": "3.0.1"
  },
  "dependencies": {
    "date-fns": "^1.28.0",
    "dayjs": "^1.8.16",
    "faker": "^4.1.0",
    "lodash": "^4.17.15",
    "node-sass": "^4.12.0",
    "react": "^16.9.0",
    "react-compound-timer": "^1.1.5",
    "react-countdown-now": "^2.1.1",
    "react-dom": "^16.9.0",
    "react-loader-spinner": "^3.1.4",
    "react-redux": "^7.1.0",
    "react-spinners": "^0.6.1",
    "redux": "^4.0.1",
    "redux-devtools-extension": "^2.13.8",
    "redux-thunk": "^2.3.0",
    "styled-components": "^4.3.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

我还尝试编写“ dependencies”开玩笑版本24.07.1,还删除了node_modules,package-lock.json,但它没有改变任何内容-相同的错误( 此外,我还添加了带有SKIP_PREFLIGHT_CHECK = true的.env文件,但它也无助于修复我的错误

有人可以帮我吗? 谢谢!

2 个答案:

答案 0 :(得分:0)

我想如果您仔细看一下这一行:

 /Users/nazarromanchuk/node_modules/jest

它是您主目录中的目录。也许您会出错并在主目录中运行npm init?您能否检查/Users/nazarromanchuk/并删除package.json和node_modules文件夹?然后在interview-questions模块中更改目录(cd),然后运行npm i或尝试使用yarn

答案 1 :(得分:0)

尝试将系统中的笑话降级到项目版本。你可以在这里找到它:

/Applications/node_modules/package.json

在节点模块目录中:npm install jest@24.7.1(项目版本)