【问题标题】:Cannot manage to install jest无法安装 jest
【发布时间】:2020-08-03 17:58:30
【问题描述】:

我正在使用npm 安装jest 以便对我的js 代码执行一些测试。 为了安装它,我使用以下命令:

$ npm install --save-dev jest

如他们网站上所述。

但是,它一次又一次地失败并出现以下错误:

我应该怎么做才能正确安装jest

这是我的 package.json :

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "babel-preset-env": "^1.7.0",
    "jest": "^23.5.0",
    "react-scripts": "0.6.1"
  },
  "dependencies": {
    "adal-angular": "^1.0.13",
    "axios": "^0.15.3",
    "bootstrap": "^3.3.7",
    "jquery": "^3.1.1",
    "lodash": "^4.16.4",
    "react": "^15.4.2",
    "react-bootstrap": "^0.30.5",
    "react-bootstrap-typeahead": "^1.2.0",
    "react-dom": "^15.4.2",
    "react-http-request": "^1.0.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "description": "This project was bootstrapped with [Create React App] 
  (https://github.com/facebookincubator/create-react-app).",
  "main": "index.js",
  "author": "",
  "license": "ISC"
}

当前消息: enter image description here

【问题讨论】:

  • 看起来与开玩笑或反应无关,我会尝试 rn -rf node_modules(或 Win 等效项)并可能清除 npm 缓存 npm cache clean --force 并重试。

标签: javascript reactjs npm jestjs npm-install


【解决方案1】:

请为此安装 react v16:

npm install --save react@^16.4.2 react-dom@^16.4.2

然后运行这个命令:

npm update --save

获取所有依赖包

【讨论】:

  • 请分享您的package.json
  • 它说 react 是 v15
  • 我确实安装了 v16.. 我应该手动更改它还是有其他方法来更新它?
  • 我现在再次这样做只是为了确保并收到上面的消息(再次编辑我的问题)
  • 我没有看到你的帖子有任何变化
【解决方案2】:

我只是删除了 node_modules 和 package-lock.json,然后使用 yarn 重新安装了所有东西。它奏效了……

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-11
    • 1970-01-01
    • 2021-07-26
    • 2020-10-12
    • 1970-01-01
    • 2023-01-30
    • 2014-01-08
    • 2011-10-17
    相关资源
    最近更新 更多