react-router/index.d.ts file in this repo and had problems.react-router/index.d.ts.My TypeScript compilation was just broken with a bunch of errors like
@types/react-router/lib/history"' has no exported member 'Location'
@types/react-router/lib/history"' has no exported member 'LocationDescriptor'
@types/react-router/lib/history"' has no exported member 'Pathname'
@types/react-router/lib/history"' has no exported member 'Path'
@types/react-router/lib/history"' has no exported member 'Query'
@types/react-router/lib/history"' has no exported member 'HistoryQueries'
@types/react-router/lib/history"' has no exported member 'QueryString'
@types/react-router/lib/history"' has no exported member 'LocationState'
@types/react-router/lib/history"' has no exported member 'Href'
Turns out, I had @types/react-router version ^2.0.44, which is the latest, but I got @types/history version 4.5.0, which is also latest, but incompatible.
I can see that this is a relatively new change (4 days ago). The package.json file of @types/react-router shows @types/history dependency with version '*'.
@types/history was advanced while @types/react-router was not.@types makes dependencies as '*' by default which may not be the optimal solutions.npm i --save-dev @types/history@^2.0.45, one version earlier, fixed the problem.
cc @benjamingr
Thanks for the workaround! With yarn I had to do one more step: remove and reinstall @types/react-router so it uses the correct version for @types/history:
yarn add @types/history@^2.0.45
yarn remove @types/react-router
yarn add @types/react-router
I just realized I might have pinged the wrong people. cc @rokoroku @andy-ms
Try install @types/react-router@^2.0.45.
I just test with this version, and It resolves @types/history@^2 correctly.
I've tried that, it didn't resolve the dependency correctly and resulted in an error. Something funky is going on here.
It didn't work when I specifically npm install --save-dev @types/react-router@^2.0.45, nor when I had that entry in package.json and just typed npm i.
@MadaraUchiha Could you share your dependencies from package.json file? There seems to be a discrepancy between type dependencies somewhere.
@rokoroku I have it fixed now in my main repo, so I can't really give you an example that I can guarantee reproduces this issue.
I'll try to set up a reduced example later today.
This should have already been fixed. npm info @types/react-router dependencies
Is there a reason why history was set to "*" in the package though?
I faced the same issue today. Solved by using "@types/history": "@^2.0.46" and "@types/react-router": "^2.0.44" and "react-router": "^2.0.44".
I tried initially installing the latest react-router 3.x.
I'm getting this issue with react-router-dom v4, I tried installing "@types/history": "@^2.0.46" and that didn't work
"@types/history": "4.7.2",
"@types/react-router": "4.4.1",
"@types/react-router-dom": "4.3.1",
I believe I am having the same issue as @hom-bahrani any help would be great thanks.
Also having issues importing History and other types from 'history'.
@types/history/index.d.ts;@types/history's package.json and it has the proper "types": "index.d.ts" - so it should work;tsconfig.json doesn't specify custom typeRoots;I'm doing import { History, Location } from 'history' and tsc is failing to compile it.
Failed to compile.
./src/Routed.ts
Attempted import error: 'History' is not exported from 'history'.
Tried downgrading the history package, but no luck. I did not try to play with package versions because I used create-react-app - I did not know if I would break anything by changing any package version manually.
npx create-react-app foobar --template typescript && cd foobar
yarn add react-router-dom
yarn add @types/react-router-dom
PS: react-router-dom depends on react-router and history, so you don't need to install those yourself.
Anyone has an idea of what else could be wrong?
For me I just solved it with this combination just now:
Most helpful comment
Is there a reason why history was set to "*" in the package though?