[英]Why does it work with npm but yarn not?
After installed packages from package.json
with yarn
, then starting yarn test
I've got the following error: 从
package.json
安装带yarn
包装,然后开始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.
When I ran with npm i
to install packages, then run the test with yarn test
, the test will pass. 当我用
npm i
运行安装包时,然后用yarn test
运行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.
The question is, what is the different, when I install my packages with yarn
or npm
. 问题是,当我用
yarn
或npm
安装我的包装时,有什么不同。
The package.json content: 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"
}
}
Give a try: 试一下:
If you have both
react-scripts
andjest
in yourpackage.json
, deletejest
from it.如果你的
package.json
同时包含react-scripts
和jest
,请从中删除jest
。 Then deletepackage-lock.json
,yarn.lock
andnode_modules
.然后删除
package-lock.json
,yarn.lock
和node_modules
。 Then runnpm install
(oryarn
if you use it).然后运行
npm install
(如果你使用它,则运行yarn
)。
So if you're using yarn, run yarn install
instead of npm install
and try again. 因此,如果您使用纱线,请运行
yarn install
而不是npm install
然后重试。
From: https://github.com/facebook/jest/issues/5119 来自: https : //github.com/facebook/jest/issues/5119
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.