next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Cannot read property 'replaceState' of undefined

Open jagreene opened this issue 9 years ago • 3 comments

On first load, my now.js hosted app works as expected but as soon I reloaded the page I was met with 503. The only addition in this version of my app is a package for recording audio in the browser RecordRTC. The error message (bellow) is a bit arcane and any advice for how to to approach it would be greatly appreciated!

TypeError: Cannot read property 'replaceState' of undefined at Router.changeState (/home/nowuser/src/node_modules/next/dist/lib/router/router.js:383:23) at new Router (/home/nowuser/src/node_modules/next/dist/lib/router/router.js:99:12) at renderPage (/home/nowuser/src/node_modules/next/dist/server/render.js:150:25) at Function.getInitialProps (/home/nowuser/src/node_modules/next/dist/server/document.js:83:25) at _callee$ (/home/nowuser/src/node_modules/next/dist/lib/utils.js:36:30) at tryCatch (/home/nowuser/src/node_modules/regenerator-runtime/runtime.js:65:40) at Generator.invoke [as _invoke] (/home/nowuser/src/node_modules/regenerator-runtime/runtime.js:303:22) at Generator.prototype.(anonymous function) [as next] (/home/nowuser/src/node_modules/regenerator-runtime/runtime.js:117:21) at step (/home/nowuser/src/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30) at /home/nowuser/src/node_modules/babel-runtime/helpers/asyncToGenerator.js:35:14

jagreene avatar May 25 '17 20:05 jagreene

What's the browser and OS. Seems like it's doesn't have HTML5 History API

It's a requirement for Next.js

arunoda avatar May 26 '17 02:05 arunoda

After doing some more poking around that's what I thought might be the issue except the error is occurring on chrome 58.0.3029.110 (64-bit) on both Arch and Windows 10 :/ which both have the History API.

jagreene avatar May 26 '17 07:05 jagreene

After digging around both sources it looks like RecordRTC was trying to mock a new window during server side rendering and that mock was missing history.

Solved the issue by conditionally requiring the package in the OnComponentDidMount of the component that needed it.

jagreene avatar May 26 '17 07:05 jagreene