Could you please help me to solve the problem with the preview? I just migrated project to v4 gatsby-source-prismic. I installed gatsby-plugin-prismic-previews. I set up previews in Prismic repository and set up previews in project code according to this guide https://prismic.io/docs/technologies/tutorial-6-preview-deploy-gatsby
Everything is working fine except the preview function. Previews do not work, when I try to see preview from Prismic repo, I have two errors in browser console:
page resources for /preview/ not found. Not rendering React
Uncaught (in promise) ReferenceError: process is not defined
The build is live. I tried to search these errors, I installed path module, but errors are still here.
I had a similar error a couple of days ago and it was because I was missing to add the _previewable field to my page queries.
Are you following the tutorial from step one or do you have a separate project? If you have your own project I recommend you read the Preview setup guide.
Is prismicRepositoryName correctly exported from gatsby-config.js? Can you log prismicRepositoryName within src/pages/preview.js to verify that withPrismicPreviewResolver is being provided with the correct configuration?
Based on your screenshot, it looks like the plugin is not detecting an active preview session. This could happen for a few reasons:
The Prismic Toolbar is not loaded. This is added automatically when gatsby-plugin-prismic-previews is configured in gatsby-config.js
The repositoryName provided to withPrismicPreviewResolver is not the same repository name as the preview token (this is setup when you click the preview button in Prismic). This could happen if the repository name was mistyped or imported incorrectly.
Hi, @angeloashmore. All 1, 2 and 3 are set up according to tutorial. Just checked them again — all three are ok, I can log pismicRepositoryName in preview.js.
Thanks for checking @dmitry.d. One more thing to look for: if you inspect the page, do you see the Prismic toolbar in the DOM? You'll see it as an element with an ID of "prismic-toolbar-v2".
@dmitry.d When you start a preview, do you still only see the iframe without the prismic-toolbar-v2 div?
It might be easier for us to debug this issue if you are able to send me your project's code. If you are comfortable with sending your code, you can send me a private message with a link to a ZIP of the project (or your Git repo if it is public). If you run into size upload limits, be sure to leave out node_modules, public, and .cache.
Thanks for this post. So far with all the info I've read, my problem is identical to @dmitry.d 's. I can't share the codebase unfortunately, so looking forward to a solution here if you come across one.
@dmitry.d Thanks for sending your code. I tested it locally with a clone of your Prismic repository and everything worked as expected. The only change I made was editing the prismicRepository value in prismic-config.js to the new repository I created.
I noticed your previews are setup for Gatsby Cloud. Can you add an additional Preview to your repository for http://localhost:8000/preview and test it locally?
I think the issue is related to:
The preview token from Prismic is not matching with the configuration in the Gatsby project. If the plugin cannot find a matching Prismic repository config in withPrismicPreviewResolver, it will do nothing since it isn't a valid preview. (Maybe this is an opportunity for the plugin to show an alert as feedback).
The toolbar is not loading or it is not setting the preview cookie. The toolbar is crucial to setting the preview token as a cookie which the plugin then reads. Do you see any warnings or errors related to privacy and/or cookie management?
@brett1 Sorry to hear you're also having issues. Once we figure out the issue, I can update the plugin to either provide better feedback to avoid the issue or fix a bug if there is one.
@dmitry.d Thanks for checking those issues. The cookie issue is something we're looking into at the moment, but it should continue to work right now. The warnings you posted will take effect in the future.
The only configuration change I made to the code you sent was the repository name in prismic-config.js. I'm leaving it out of this post to keep it private.
Could you check if your repository needs the new or legacy toolbar? You can do this by going to the Previews section of your Prismic repository's settings.
If you see new=true, then there is no special setup required. If you do not see new=true, you will need to configure gatsby-plugin-prismic-previews to use the legacy toolbar.