Monorepo:Yarn 工作区不工作 - 依赖包未安装在 node_modules

Monorepo: Yarn workspaces not working - dependent package doesn't get installed in node_modules

我正在使用带有 Typescript 的 Yarn Workspaces 创建的 monorepo,它有一个 react-native 项目(mobile 文件夹)和一个 common 文件夹其中包含要跨项目共享的公共文件。这里的 mobile 项目依赖于 common 文件,我已经参考这个 doc.

配置了它

当我执行 yarn install 时显示此错误 -> An unexpected error occurred: "https://registry.yarnpkg.com/@myapp%2fcommon: Not found".

Monorepo 结构:

packages
|---package.json
|---Common
|      |---src
|      |---package.json
|---Mobile
|      |---src
|      |---package.json

root package.json

{
"name": "monorepo",
"version": "0.0.1",
"private": true,
"workspaces": {
    "packages": ["packages/*"],
    "nohoist": [
        "**/react-native",
        "**/react-native/**",
    ]
}
}

普通的package.json

{
"name": "@myapp/common",
"version": "0.0.1",
"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1"
},
"license": "UNLICENSED",
"devDependencies": {
  "@types/react": "18.0.9",
  "@types/react-native": "0.67.7",
  "@reduxjs/toolkit": "1.8.1",
  "react-redux": "8.0.1"
}
}

手机的package.json (react-native)

"name": "@myapp/mobile",
"version": "0.0.1",
"private": true,
...
"dependencies": {
    "@myapp/common": "0.0.1",
    "@reduxjs/toolkit": "1.8.1",
    "react": "17.0.2",
    "react-native": "0.68.2",
    ...
}
...

有什么建议吗?

您的 root package.json 并不是真正的 root。确保您的文件夹结构如下所示:

package.json 
packages 
|---Common
|...