简体   繁体   English

找不到命令:react-scripts(PS:yarn2(berry)工作区)

[英]command not found: react-scripts (PS: yarn2(berry) workspaces)

Working on a yarn2 powered monorepo with two workspaces common and app .在具有两个工作区commonapp的 yarn2 驱动的 monorepo 上工作。 I've declared typescript and react-scripts as devDependencies in root's package.json ;我在 root 的 package.json 中将typescriptreact-scripts声明为 devDependencies; and declared typescript and react-scripts as peerDependencies in app's package.json.并在应用程序的 package.json 中将typescriptreact-scripts声明为 peerDependencies。

However, running yarn start gives the error但是,运行yarn start会出现错误

command not found: react-scripts

Any idea how to go about this?知道该怎么做吗?

Sidenote边注

react-scripts has peerDependencies on react which I've provided in root workspace's dependency section. react-scripts 对我在根工作区的依赖部分提供的react有 peerDependencies。

attaching package.json for root:为 root 附加 package.json:

{
  "name": "monorepo",
  "packageManager": "yarn@3.2.1",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.4",
    "@testing-library/react": "^13.3.0",
    "@testing-library/user-event": "^13.5.0",
    "@types/jest": "^27.5.2",
    "@types/node": "^16.11.43",
    "@types/react": "^18.0.15",
    "@types/react-dom": "^18.0.6",
    "fictoan-react": "^0.41.22",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "styled-components": "^5.3.5",
    "web-vitals": "^2.1.4"
  },
  "devDependencies": {
    "react-scripts": "5.0.1",
    "typescript": "^4.7.4"
  },
  "workspaces": [
    "common",
    "app"
  ]
}

package.json for app应用程序的 package.json

{
  "name": "app",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "dependencies": {
    "common": "workspace:*"
  },
  "peerDependencies": {
    "@testing-library/jest-dom": "*",
    "@testing-library/react": "*",
    "@testing-library/user-event": "*",
    "@types/jest": "*",
    "@types/node": "*",
    "@types/react": "*",
    "@types/react-dom": "*",
    "fictoan-react": "*",
    "react": "*",
    "react-dom": "*",
    "react-scripts": "*",
    "styled-components": "*",
    "web-vitals": "*"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

Not sure if this is a hack, but solved this using https://yarnpkg.com/getting-started/qa#how-to-share-scripts-between-workspaces不确定这是否是黑客攻击,但使用https://yarnpkg.com/getting-started/qa#how-to-share-scripts-between-workspaces解决了这个问题

added this to root's package.json将此添加到根的 package.json

 "scripts": {
    "g:start": "cd $INIT_CWD && react-scripts start",
    "g:build": "cd $INIT_CWD && react-scripts build",
    "g:test": "cd $INIT_CWD && react-scripts test",
    "g:eject": "cd $INIT_CWD && react-scripts eject"
  }

updated this in app's package.json在应用程序的 package.json 中更新了这个

 "scripts": {
    "start": "yarn g:start",
    "build": "yarn g:build",
    "test": "yarn g:test",
    "eject": "yarn g:eject"
  }

PS:not really sure why react-scripts isn't available in app workspace even though its specified as a peerDependency :/ PS:不确定为什么react-scripts在应用程序工作区中不可用,即使它被指定为peerDependency :/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有使用 react-scripts 和 jest 找到测试 - No tests found using react-scripts and jest 'react-scripts' 未被识别为内部或外部命令 - 'react-scripts' is not recognized as an internal or external command react-scripts babel 脚本在本地反应应用程序上使用纱线运行时出错 - react-scripts babel scripts error running with yarn on local react application 带有 React 和 React Native 的 Yarn 工作区 - Yarn workspaces with React and React Native React-react-scripts publicPath - React - react-scripts publicPath Npm 模块未安装并引发此错误:'react-scripts' 未被识别为内部或外部命令, - Npm modules not getting installed and throws this error: 'react-scripts' is not recognized as an internal or external command, 'react-scripts' 未被识别为内部或外部命令、可运行程序或批处理文件 - 2022 - 'react-scripts' is not recognized as an internal or external command, operable program or batch file - 2022 在 CRA/react-scripts 中使用可选链接 (?.) - using optional chaining(?.) with CRA/react-scripts 了解 react-scripts 如何开始工作 - Understanding how react-scripts start work npm 安装:反应脚本安装失败 - npm install: react-scripts install fails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM