TypeError: Cannot read property 'pathname' of undefined withPreview gatsby-source-prismic

I have been using gatsby-source-prismic and with the withPreview I get an error as follows

Hi Dennis,

Welcome to Prismic community,

The Gatsby plugin that we support currently is the gatsby-source-prismic-graphql and here is link to our documentations that uses this plugin.

In order to be able to debug this issue, can you tell me if you have added a LinkResolver file and used it? if so then can you share a code snippet of the link usage you are trying to display, you GraphQL query and the linkResolver file?

Looking forward to your reply,
Fares

image

You should sync better with the staff :slight_smile:

Yes we have discussed about that internally and thanks for letting us know :+1:

In fact switching plugins is already a hot topic and it seems the
gatsby-source-prismic is implemented in a way that works well with Gatsby cloud.

But nothing has been decided and we are still supporting the gatsby-source-prismic-graphql plugin until we communicate about that, along with adding some new documentations.

Can you provide a working example for the gatsby-source-prismic-graphql ? I have tried it as well, but it doesn’t fetch previews, especially on private access.

Hi Dennis,

Preview don’t currently work for this kit when repositories are set to private, we discuss that here:
https://prismic.io/docs/gatsby/misc-topics/previews

You can check out our Gatsby blog sample which has everything configured correctly:

I get error when i try to install node modules in that sample project:
npm ERR! Could not install from "..\..\..\..\shared" as it does not contain a package.json file.

Hello Dennis, a quick update about using gatsby plugins with Prismic, please look at this thread where we address this topic more broadly:

Hi Dennis,

I’ve just tried to install the node modules on our sample blog and it does install all dependencies successfully!

It seems that you have either modified the sample by importing the “…\shared” without including it in package.json (if it is a git submodule dependency) or you have deleted the package.json.

Best,
Fares

Thanks for this link and clarifying the issues with gatsby prismic previews. I havent been able to get a clear answer yet on how to work the previews, but as I understand from this, Prismic Previews do not work with Gatsby yet, right?

And this contradicts the reply from @Fares about using gatsby-source-prismic-graphql, right?

And Previews doesnt work at all regardless of repo being set to private or public, right?

Hi @dennis
Let me clarify, the multisession preview can still work if you use our fork of gatsby-source-prismic-graphql.
As mentioned in the blog post shared before we don’t recommend this plugin for new projects.

If you need a plugin that is a future proof solution that is recommended by Prismic, then I would advise you to use the gatsby-source-prismic
Note that multisession previews feature don’t work currently with this plugin.

Furthermore, if you need to use more stable SSR that works with multisession previews then I would advise you to use Next.js

Please let us know if need any further assistance.

what about just normal “single session” previews for one person? does this plugin support that? I’ve attempted to set it up using the detailed instructions, but all I get is a redirect to the page I want to preview with the “old” content.

Hi Matt,

Yes the gatsby-source-prismic supports “single session” previews and I will be happy to help you debug this issue.

First of all, did you create a preview in your Prismic repository settings? if you didn’t please follow this article

If that’s not the issue then can you please share with as code snippet or your code where you configure your previews as well as the failing page code that is failing to preview.

Looking forward to your reply,
Fares

Hi @Fares
is the gatsby-plugin-prismic still the preferred choice for creating new projects or is there any news about @prismicio/gatsby-source-prismic-graphql plugin?

Thank you
Simone

Hi Simone,

Yes in fact our stand of @prismicio/gatsby-source-prismic-graphql plugin didn't change and still advise users to use gatsby-plugin-prismic for new projects.

This issue has been closed due to inactivity. Flag to reopen.