[Bug] Typescript support for workspaces
See original GitHub issueDescribe the bug
I’m not sure if this is a yarn 2 bug or a CRA bug, but I cannot use typescript with CRA when using workspaces (it works just fine without workspaces).
To Reproduce See https://github.com/alubbe/yarn2_workspace_typescript
Here’s the version, without workspaces, that works just fine: https://github.com/alubbe/yarn2_workspace_typescript/tree/5a902ae8e3b39aa33e9c84ed0000b88fdc7bb9c5 The repo was created by these commands:
npx create-react-app pnp --use-pnp --typescript
yarn set version berry
yarn install
// ... add `connected-react-router`
Then, I simply move the files into a workspace (https://github.com/alubbe/yarn2_workspace_typescript/commit/7839493116b4df41a7dfd328b9819116d20d1cff), and suddenly I get this error:
TypeScript error in undefined(undefined,undefined):
Cannot find type definition file for 'node'.
So I fix ts-pnp
by unplugging (see https://github.com/arcanis/pnp-webpack-plugin/issues/14#issuecomment-534132701 and https://github.com/alubbe/yarn2_workspace_typescript/commit/4c062a19b5515853699ccda95d671b3e990bb6e7), but I cannot get past this error:
TypeScript error in /packages/rofl/src/index.tsx(10,5):
JSX element class does not support attributes because it does not have a 'props' property. TS2607
8 | ReactDOM.render(
9 | <React.StrictMode>
> 10 | <ConnectedRouter history={{}}>
| ^
11 | <App />
12 | </ConnectedRouter>
13 | </React.StrictMode>,
So, it looks like TypeScript can find types from @types just fine, but not from a package itself (connected-react-router
has its own types file). Am I doing something wrong or is this a bug?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:6 (5 by maintainers)
Thank you all - you’ve helped me resolve the issue! Two quick notes for anyone else finding this thread in the future:
@types/redux
still exists and using it fixed the error, it is deprecated and its types are no longer compatible withredux
. I got a complicated type error later on becauseredux
now ships its own types file - so I just replaced@types/redux
withredux
as a dependency ofconnected-react-router
connected-react-router
only seemed to need the extra@types/react
dependency. So for us, this was the final fix:Sorry about not getting to this sooner, I looked into it and the issues here are:
ts-pnp
is outdated, you fixed this by unplugging and applying the fix manually, however you can also set this in yourpackage.json
connected-react-router
is missing some dependencies (as hinted to by @backslash47 in https://github.com/yarnpkg/berry/issues/1483#issuecomment-649566062) You can fix these by adding this to your.yarnrc.yml
fileThe reason it works without workspaces is that you declared these dependencies yourself at the root and because of the fallback (https://yarnpkg.com/configuration/yarnrc#pnpFallbackMode) it was allowed to use those