4

i'm trying to convert an inherited monorepo from yarn+lerna to pnpm workspaces

i'm currently getting an error due to mismatching react versions, typescript isn't picking up on the @types/react version that's closest in the tree for some reason

i have a packages/web package that uses react 18 types, and a packages/native package that uses react 16 types.

i have loads of errors in the native package like

'Text' cannot be used as a JSX component.
  Its instance type 'Text' is not a valid JSX element.
    The types returned by 'render()' are incompatible between these types.
      Type 'import("~/node_modules/.pnpm/@types+react@16.14.34/node_modules/@types/react/index").ReactNode' is not assignable to type 'import("~/node_modules/.pnpm/@types+react@18.0.14/node_modules/@types/react/index").ReactNode'.

any idea how to fix this?

  • just a wild guess, but it might be due to the fact that Yarn probably hoisted everything and pnpm hoist nothing by default, you can try [shamefully-hoist](https://pnpm.io/npmrc#shamefully-hoist) – ghiscoding Nov 01 '22 at 13:36
  • 4
    Did you ever figure it out? I am facing the same issue. I also have one package with React 16 and another with React 18. – Frederik Claus Nov 25 '22 at 20:06
  • @Tom did you had any luck with this? – Alwaysblue Jul 17 '23 at 19:20

2 Answers2

0

Run pnpm update --latest -r to recursively update all dependencies to the latest version. This should make all packages use unifirm versions and resolve all or most of the errors.

Mayank Kumar Chaudhari
  • 16,027
  • 10
  • 55
  • 122
0

Sometimes, old dependencies might cause conflicts. To ensure you have a clean environment, try clearing the pnpm cache by running this command:

pnpm cache clear --force
Bernardo Almeida
  • 419
  • 4
  • 12