【问题标题】:Why does it work with npm but yarn not?为什么它可以与 npm 一起使用,但 yarn 不行?
【发布时间】:2018-09-22 15:36:42
【问题描述】:

package.jsonyarn 安装包后,然后从yarn test 开始,出现以下错误:

FAIL  src/Dashboard/AppBar/Tests/AppBar.test.js
  ● Test suite failed to run

    TypeError: environment.setup is not a function

      at node_modules/jest-runner/build/run_test.js:71:23

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.478s
Ran all test suites related to changed files.

当我使用npm i 运行安装包,然后使用yarn test 运行测试时,测试将通过。

 PASS  src/Dashboard/AppBar/Tests/AppBar.test.js
  ✓ renders (92ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.452s, estimated 2s
Ran all test suites related to changed files.

Watch Usage: Press w to show more.  

问题是,当我使用yarnnpm 安装我的软件包时,有什么不同。

package.json 内容:

{
  "name": "sample",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "bs-axios": "^0.0.34",
    "material-ui": "^1.0.0-beta.41",
    "react": "^16.3.1",
    "react-dom": "^16.3.1",
    "react-scripts": "1.1.4",
    "reason-react": "^0.3.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "mlbuild": "bsb -make-world",
    "mlstart": "bsb -make-world -w",
    "mlclean": "bsb -clean-world"
  },
  "devDependencies": {
    "bs-platform": "^2.2.3",
    "enzyme": "^3.3.0",
    "enzyme-adapter-react-16": "^1.1.1",
    "jest": "^22.4.3"
  }
}

【问题讨论】:

    标签: javascript npm yarnpkg


    【解决方案1】:

    试一试:

    如果您的package.json 中有react-scriptsjest,请从中删除jest。然后删除package-lock.jsonyarn.locknode_modules。然后运行npm install(或yarn,如果你使用它)。

    因此,如果您使用的是 yarn,请运行 yarn install 而不是 npm install,然后重试。

    发件人:https://github.com/facebook/jest/issues/5119

    【讨论】:

      猜你喜欢
      • 2011-07-04
      • 2018-04-07
      • 2019-06-19
      • 1970-01-01
      • 2017-05-16
      • 1970-01-01
      • 1970-01-01
      • 2017-01-31
      • 2021-11-15
      相关资源
      最近更新 更多