question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Typescript support for workspaces

See original GitHub issue

Describe 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:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
alubbecommented, Jul 26, 2020

Thank you all - you’ve helped me resolve the issue! Two quick notes for anyone else finding this thread in the future:

  1. While @types/redux still exists and using it fixed the error, it is deprecated and its types are no longer compatible with redux. I got a complicated type error later on because redux now ships its own types file - so I just replaced @types/redux with redux as a dependency of connected-react-router
  2. After everything was building, I noticed that (at least for our code base) connected-react-router only seemed to need the extra @types/react dependency. So for us, this was the final fix:
  connected-react-router@^6.5.2:
    dependencies:
      "@types/react": ^16.9.2
1reaction
merceyzcommented, Jul 19, 2020

Sorry about not getting to this sooner, I looked into it and the issues here are:

  • The version of ts-pnp is outdated, you fixed this by unplugging and applying the fix manually, however you can also set this in your package.json
"resolutions": {
  "ts-pnp": "^1.2.0"
}
packageExtensions:
  "connected-react-router@*":
    dependencies:
      "@types/react": "*"
      "@types/redux": "*"
      "@types/react-redux": "*"
      "@types/react-router": "*"
      "@types/history": "*"  

The 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript Programming with Visual Studio Code
TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. It offers classes, modules, and interfaces to help you build robust...
Read more >
A guide through The Wild Wild West of setting up a mono repo ...
In this part, I will explain step by step how to setup Lerna, Yarn Workspaces and Typescript in a mono repo. In the...
Read more >
Typescript auto completion, auto imports, tooltips, etc. don't ...
1. Create a typescript project with npm/yarn workspaces (npm version 7+, yarn version 1.22+). 2. Add a workspace with package.
Read more >
NPM Workspaces Typescript unable to find local modules
no error after change. For other considerations, like specific compiler options or esm support, consult the document ECMAScript Modules in ...
Read more >
Function from other workspace not found (2307) : r/typescript
I tried getting a minimal project based on yarn workspaces to run, however when I try calling a function from another workspace, TypeScript...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found