create-react-app devDependencies没有放在正确的位置

mjqavswn  于 2022-10-28  发布在  React
关注(0)|答案(4)|浏览(133)

React版本:LTS系统

重现步骤

运行npx create-react-app my-app --template typescript
检查package.json

当前行为

相关性显示如下:

"dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "@types/jest": "^26.0.15",
    "@types/node": "^12.0.0",
    "@types/react": "^17.0.0",
    "@types/react-dom": "^17.0.0",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-scripts": "4.0.3",
    "typescript": "^4.1.2",
    "web-vitals": "^1.0.1"
  }

预期行为

"dependencies": {
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-scripts": "4.0.3",
    "web-vitals": "^1.0.1"
  },
  "devDependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "@types/jest": "^26.0.15",
    "@types/node": "^12.0.0",
    "@types/react": "^17.0.0",
    "@types/react-dom": "^17.0.0",
    "typescript": "^4.1.2"
  }
wnavrhmk

wnavrhmk1#

在此之前,为了保存未来读者的时间:
x1m0n1x
npm install -D @testing-library/jest-dom @testing-library/react @testing-library/user-event @types/jest @types/node @types/react @types/react-dom typescript

yqyhoc1h

yqyhoc1h2#

我还假设react-scripts是一个devDependency。

khbbv19g

khbbv19g3#

此问题已自动标记为过时,因为它最近没有任何活动.如果没有进一步得活动,它将在5天内关闭.

iugsix8n

iugsix8n4#

你好!我在我的申请表上也看到了这个,你能帮我分类一下吗?谢谢!
另外,与安装testing-library/react和jest-dom相关的文档提到我们应该使用“--保存”而不是“--save-dev”,这样做有什么具体的原因吗?

相关问题