The inferred type of "X" cannot be named without a reference to "Y". This is likely not portable. A type annotation is necessary.
See original GitHub issueBug Report
š Search Terms
inferred type cannot be named, symlink node_modules
š Version & Regression Information
Iām verifying the problem on the typescript@4.1.3
. Iāve not tried older versions but at least is also reproducible on the @next
version as of today.
It is probably a regression or a corner case related with other issues opened and already closed like:
- https://github.com/microsoft/TypeScript/issues/30858
- https://github.com/microsoft/TypeScript/issues/28689
- https://github.com/microsoft/TypeScript/issues/2338
- https://github.com/microsoft/TypeScript/issues/29221
āÆ Playground Link
Link for a repo where the problem is being reproduced
NOTE: Just clone the repo and run
yarn tsc
š» Code
All the relevant code can be found at https://github.com/mistic/reproduce-typescript-problem-when-symlinking-node_modules
It is just reproducing a similar setup that I had on other project that was generating the problem:
- node_modules are a symlink to another location that is not a direct parent of the symlinked node_modules
- we are using types in the compilation from a library where those types are just exported from other one, like for example
withRouter
withinreact-router-dom
that is just a plain export from the same type onreact-router
.
š Actual behavior
I got the following error:
error TS2742: The inferred type of 'Nav' cannot be named without a reference to '../../deps/node_modules/@types/react-router'. This is likely not portable. A type annotation is necessary.
8 export const Nav = withRouter(({ history }: NavProps) => {
~~~
Found 1 error.
š Expected behavior
I was expecting no error at all and that the typescript compiler was just able to find all the respective modules. Iāve tried everything that I thought was related like enabled the preserveSymlinks
. The only thing that stops the error is importing the withRouter
type directly from react-router
and not from react-router-dom
but that doesnāt make very sense because I actually want to use the react-router-dom
on a couple of places.
\cc @weswigham @sheetalkamat @andrewbranch because I saw you previously worked to try to solve similar issues.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:77
- Comments:65 (3 by maintainers)
Top GitHub Comments
I get this issue throughout many scenarios when using a Rush monorepo. Rush, by default, uses pnpm (pnpm workspaces is recommended). I havenāt been able to track down the root cause, but I have scoured this issue tracker and subscribed to many topics hoping someone squashes this.
In my case, add
preserveSymlinks
for resolve it