Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecated warning with Express #80

Closed
lemonCMS opened this issue Oct 6, 2015 · 2 comments
Closed

Deprecated warning with Express #80

lemonCMS opened this issue Oct 6, 2015 · 2 comments

Comments

@lemonCMS
Copy link

lemonCMS commented Oct 6, 2015

I am using the latest history version

"history": "1.12.1",

With Express i am getting the following warning

Warning: createLocation is deprecated; use history.createLocation instead

In the clientside code this was easy to fix

const history = require('history');
const historyObj = history.createHistory();

historyObj.createLocation(....)

When you try to run this code with express you will get the following error

[1] [piping] error given was: Error: Invariant Violation: Browser history needs a DOM
[1]     at Object.invariant [as default] (/var/www/webapp/node_modules/history/node_modules/invariant/invariant.js:44:15)
[1]     at Object.createBrowserHistory [as createHistory] (/var/www/webapp/node_modules/history/lib/createBrowserHistory.js:35:25)
[1]     at Object.<anonymous> (/var/www/webapp/src/server.js:5:28)
[1]     at Module._compile (module.js:434:26)
[1]     at normalLoader (/var/www/webapp/node_modules/babel-core/lib/api/register/node.js:199:5)
[1]     at Object.require.extensions.(anonymous function) [as .js] (/var/www/webapp/node_modules/babel-core/lib/api/register/node.js:216:7)
[1]     at Module.load (module.js:355:32)
[1]     at Module._load (module.js:310:12)
[1]     at Function.module._load (/var/www/webapp/node_modules/piping/lib/launcher.js:32:16)
[1]     at Module.require (module.js:365:17)
[1] [piping] further repeats of this error will be suppressed...

So how can we use createLocation with express?

@Justkant
Copy link

Justkant commented Oct 6, 2015

Same problem for me

@mjackson
Copy link
Member

mjackson commented Oct 6, 2015

In a non-DOM environment (like node) you need to use a "memory history", not a "browser history".

const history = require('history');
const historyObj = history.createMemoryHistory();

historyObj.createLocation(....)

This is because browser history needs to setup a listener for the popstate event. But memory history just keeps everything in memory.

@mjackson mjackson closed this as completed Oct 6, 2015
@asaf asaf mentioned this issue Oct 8, 2015
@lock lock bot locked as resolved and limited conversation to collaborators Jun 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants