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

Cannot read property 'pathname' of undefined #31

Closed
AndrewRayCode opened this issue Apr 8, 2019 · 12 comments
Closed

Cannot read property 'pathname' of undefined #31

AndrewRayCode opened this issue Apr 8, 2019 · 12 comments

Comments

@AndrewRayCode
Copy link

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

@adamsoffer
Copy link
Owner

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.

@adamsoffer
Copy link
Owner

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

@amitschandillia
Copy link

amitschandillia commented Jul 26, 2019

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...

@amitschandillia
Copy link

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?

@adamsoffer
Copy link
Owner

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

@amitschandillia
Copy link

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

@yzhang-indeed
Copy link

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.

@adamsoffer
Copy link
Owner

Hey guys, this was resolved with v3.1.2.

@amitschandillia
Copy link

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?

@adamsoffer
Copy link
Owner

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.

@amitschandillia
Copy link

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.

@adamsoffer
Copy link
Owner

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants