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.

Uncaught TypeError: history.getCurrentLocation is not a function at syncHistoryWithStore

See original GitHub issue

I have spent a couple of days trying to work around all the various issues with Typings and versions for history, react-router, mobx-react-router trying to find a combination that works… without success.

I believe I have the Typescript issues sorted, but I have the following error message during execution:

Uncaught TypeError: history.getCurrentLocation is not a function
    at syncHistoryWithStore (main-client.js:8204)

Which occurs at the following, with this line and the imports copied and pasted from the example:

const history = syncHistoryWithStore(browserHistory, routingStore);

Everything else works fine if I comment out that line, and just use the same browserHistory in the Router.

I have tried just about every combination of versions. My current package.json is as follows:

{
  "name": "NetCoreReactMobX",
  "version": "0.0.0",
  "license": "MIT",
  "dependencies": {
    "@types/history": "^4.5.0",
    "@types/react": "^15.0.14",
    "@types/react-dom": "^0.14.14",
    "@types/webpack": "^2.2.0",
    "@types/webpack-env": "^1.13.0",
    "aspnet-prerendering": "^2.0.0",
    "aspnet-webpack": "^1.0.27",
    "aspnet-webpack-react": "^1.0.4",
    "awesome-typescript-loader": "^3.0.0",
    "babel-core": "^6.5.2",
    "babel-loader": "^6.2.3",
    "babel-plugin-mobx-deep-action": "^1.5.2",
    "babel-preset-es2015": "^6.5.0",
    "babel-preset-react": "^6.5.0",
    "bootstrap": "^3.3.6",
    "css-loader": "^0.26.2",
    "domain-task": "^3.0.0",
    "event-source-polyfill": "^0.0.9",
    "extract-text-webpack-plugin": "^2.0.0-rc",
    "file-loader": "^0.10.1",
    "history": "3.2",
    "jquery": "^2.2.1",
    "json-loader": "^0.5.4",
    "mobx": "^3.1.2",
    "mobx-react": "^4.1.1",
    "mobx-react-router": "^3.1.2",
    "node-noop": "^1.0.0",
    "react": "^15.3.2",
    "react-dom": "^15.3.2",
    "react-router": "^3.0.2",
    "style-loader": "^0.13.0",
    "typescript": "^2.2.1",
    "url-loader": "^0.5.7",
    "webpack": "^2.2.1",
    "webpack-hot-middleware": "^2.12.2",
    "webpack-merge": "^3.0.0"
  },
  "devDependencies": {
    "babel-plugin-transform-class-properties": "^6.23.0",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-preset-stage-2": "^6.22.0"
  }
}

And my tsconfig.json is as follows (note I use TypeScript to ES6, then Babel to ES5)

{
  "compilerOptions": {
    "baseUrl": ".",
    "moduleResolution": "node",
    "target": "es6",
    "jsx": "preserve",
    "experimentalDecorators": true,
    "sourceMap": true,
    "allowJs": false,
    "skipDefaultLibCheck": true,
    "lib": ["es6", "dom"],
    "types": [ "webpack-env" ],
    "paths": {
      // Fix "Duplicate identifier" errors caused by multiple dependencies fetching their own copies of type definitions.
      // We tell TypeScript which type definitions module to treat as the canonical one (instead of combining all of them).
      "history": ["./node_modules/@types/history/index"],
      "react": ["./node_modules/@types/react/index"]
    }
  },
  "awesomeTypescriptLoaderOptions": {
    "silent": true,
    "useBabel": true,
    "useCache": false
  },
  "exclude": [
      "bin",
      "node_modules"
  ]
}

Any pointers would be really appreciated…

Also, is there a possibility of a sample project, that can be used as a reference point with compatible versions of mobx-react-router, history and react-router? It was a nightmare to get rid of TypeScript warnings.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
alisd23commented, Mar 9, 2017

Thanks for looking into this.

I agree the typescript ecosystem is really fragile at the moment, and types are always out of sync, due to the fact libraries like this have to try to keep the types up to date - with their own code, and libraries they depend on.

And thanks @rokoroku for the cool boilerplate. That’ll help people with similar issues out 👍

1reaction
rokorokucommented, Mar 6, 2017

@mcquiggd If you want a clean solution using mobx-react-router without TypeScript errors, try my example: https://github.com/rokoroku/react-mobx-typescript-boilerplate . react-router@4 is expected to be used as DOM objects, but mobx-react-router@4 will still be available through history synching.

Hope it helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

error history.getCurrentLocation is not a function #39 - GitHub
Hi :) I've add mobx-react-router to my project, but i've this error when i instance my store : Uncaught TypeError: history.
Read more >
react-router 1.0 Error: Uncaught TypeError ... - Stack Overflow
Getting Uncaught TypeError: getCurrentLocation is not a function in createHistory.js while implementing react-router. What is wrong in my code?
Read more >
React router v5 - TypeError history is undefined
Recently I was adding react router (version 5.1.7) to my side project. I wanted to add a redirect after a certain button is...
Read more >
uncaught typeerror: (0 , react__ ...
useHistory) is not a function (React.js) [duplicate] Ask Question Asked 10 months ago. ... Uncaught TypeError: navigator.block is not a function at ...
Read more >
How to use the history.createHistory function in history - Snyk
To help you get started, we've selected a few history. ... getCurrentLocation() console.log(pathname) console.log(query) console.log(search) ...
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