adamsoffer/next-apollo

Cannot read property 'pathname' of undefined

Closed this issue · 12 comments

I can't use this library because of the dependency issues, but when I copied most of the source code into my program, I started getting

Cannot read property 'pathname' of undefined

I believe it's because you need to pass the router object as a prop, and I'm not sure if you need it in context. I'm referring to your line: https://github.com/adamsoffer/next-apollo/blob/master/src/withData.js#L43

VS in https://github.com/zeit/next.js/blob/canary/examples/with-apollo/lib/with-apollo-client.js#L27 they pass it as a prop

Interesting. If I recall I needed router in context to support prefetching for some reason. I'll make sure to pass it as a prop as well in a hotfix.

So passing router as a prop doesn't fix the issue. Hmm. Not sure what's goin on here...

Hey Adam, were you able to resolve this one? I've been struggling with the same issue for a while now and have even posted to StackOverflow (here: https://stackoverflow.com/questions/57094132/mysterious-typeerror-while-running-next-apollo-react-apollo) with zero answers so far. My code is pretty short:

import { HttpLink } from 'apollo-link-http';
import { withData } from 'next-apollo';
import { InMemoryCache } from 'apollo-cache-inmemory';

// Set up cache.
const cache = new InMemoryCache();

// Configure Apollo.
const config = {
  link: new HttpLink({
    uri: 'https://dev.schandillia.com/graphql', // Server URL
  }),
  cache,
};
export default withData(config);

So passing router as a prop doesn't fix the issue. Hmm. Not sure what's goin on here...

I can't use this library because of the dependency issues, but when I copied most of the source code into my program, I started getting

Cannot read property 'pathname' of undefined

I believe it's because you need to pass the router object as a prop, and I'm not sure if you need it in context. I'm referring to your line: https://github.com/adamsoffer/next-apollo/blob/master/src/withData.js#L43

VS in https://github.com/zeit/next.js/blob/canary/examples/with-apollo/lib/with-apollo-client.js#L27 they pass it as a prop

Did you find a solution yet, Andrew?

Hey @amitschandillia - turns out this is actually an issue with next. There’s an open issue for it here: vercel/next.js#6042

Ahh...at least that's some pointer in the right direction. Thanks! :)

Hey @adamsoffer, I'm wondering if you are still looking into this issue? Currently I'm unable to SSR pages with dynamic url because the render method is called twice. The first time the router object is undefined.

Hey guys, this was resolved with v3.1.2.

Hey Adam, sorry for resurrecting a closed issue but I just updated to v3.1.2 and got hit by this error:

Module not found: Can't resolve '@apollo/react-ssr' in '/home/ubuntu/proost/web/node_modules/next-apollo/dist'

Am I missing something?

Yeah I forgot to add @apollo/react-ssr as a peer dep to the package. My bad.

Install v3.1.4 and then install @apollo/react-ssr as a peer dep. I just updated the README to reflect this.

Ugh...now there's an invariant violation:

Error while running getDataFromTree { Invariant Violation: Minified React error #130; visit https://reactjs.org/docs/error-decoder.html?invariant=130&args[]=undefined&args[]= for the full message or use the non-minified dev environment for full errors and additional helpful warnings.

@amitschandillia - check out the next-apollo-example repo. It's using next-apollo v3.1.4 and working on my end. Can you try cross-referencing your dependencies with that project and see if you're missing anything?