首页 > 解决方案 > Nestjs 在 monorepo 中获取 @types/react 错误

问题描述

我正在使用 Yarn 工作区使用 monorepo 工作我的后端(使用 Nestjs)和我当前的前端(使用 Tailwind 的 CRA,我将来还会添加一个 React Native 应用程序),我设法解决了我的 React 应用程序的一些问题,并且它现在正常启动,但现在我的 Nestjs 应用程序正在抛出有关@types/react.

这是我尝试启动后端应用程序时出现的一小部分错误。

../node_modules/@types/react-dom/node_modules/@types/react/index.d.ts:3244:13 - error TS2717: Subsequent property declarati
ons must have the same type.  Property 'view' must be of type 'SVGProps<SVGViewElement>', but here has type 'SVGProps<SVGVi
ewElement>'.

3244             view: React.SVGProps<SVGViewElement>;
                 ~~~~

  ../node_modules/@types/react/index.d.ts:3245:13
    3245             view: React.SVGProps<SVGViewElement>;
                     ~~~~
    'view' was also declared here.
../node_modules/@types/react/index.d.ts:3057:14 - error TS2300: Duplicate identifier 'LibraryManagedAttributes'.

3057         type LibraryManagedAttributes<C, P> = C extends React.MemoExoticComponent<infer T> | React.LazyExoticComponent
<infer T>
                  ~~~~~~~~~~~~~~~~~~~~~~~~

  ../node_modules/@types/react-dom/node_modules/@types/react/index.d.ts:3054:14
    3054         type LibraryManagedAttributes<C, P> = C extends React.MemoExoticComponent<infer T> | React.LazyExoticCompo
nent<infer T>
                      ~~~~~~~~~~~~~~~~~~~~~~~~
    'LibraryManagedAttributes' was also declared here.

Found 177 error(s).

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

这是我的 monorepo 的配置和结构。

.
├── assets
├── mobile-app
├── mobile-pwa <-- Not yet included in the packages.
├── nest-backend
├── node_modules
├── package.json
├── readme.md
└── yarn.lock

5 directories, 3 files

package.json

{
  "name": "foo",
  "private": true,
  "workspaces": {
    "packages": ["nest-backend", "mobile-pwa"]
  },
  "nohoist": ["**/**"]
}

React 应用程序package.json(将省略一些内容,因为它非常大)

{
  "name": "@foo/mobile-pwa",
  "version": "0.0.1",
  "private": true,
  "license": "UNLICENSED",
}

还有 Nest.js 后端package.json

{
  "name": "@beextravel/nest-backend",
  "version": "0.0.1",
  "description": "",
  "author": "",
  "private": true,
  "license": "UNLICENSED",

}

标签: node.jsreactjsnestjsmonorepoyarn-workspaces

解决方案


尝试:

"workspaces": {
    "packages": ["nest-backend", "mobile-pwa"],
    "nohoist": ["**/**"]
}

来源:https ://classic.yarnpkg.com/blog/2018/02/15/nohoist/


推荐阅读