Hey there,
Please do bare with me as I am a designer learning to code.
I am trying to use Prismic in a project to learn how to create next.js sites and webapps.
I'm getting pretty stuck early on when it comes to importing createClient from prismicio
I'm following this guide. Fetch Data in Next.js - Documentation - Prismic
I get the following warning:
./pages/index.js:6:0
Module not found: Can't resolve '@/prismicio'
I've also tried import { createClient } from "../prismicio";
which then leads to another error.
The code I am using createClient for is the following:
export async function getServerSideProps(ctx){
const client = createClient();
const homepage = await client.getSingle('homepage');
console.log(homepage)
return {
props:{}
}
}
and I get the following errors on my localhost:
Any ideas what I could be doing wrong here?
Some more info:
I've also tried following this guide here: https://www.locofy.ai/blog/building-a-blog-app-from-a-figma-design-with-locofy.ai
Where I run into the same issues.
Here is an image of the custom type:
Hi Will,
I have seen this issue before. Check your prismicio.js file and look for your route resolver.
Comment out your page route, and leave the homepage route there:
const routes = [
{
type: 'homepage',
path: '/',
},
// {
// type: 'page',
// path: '/:uid',
// },
]
Let me know if that helps.
szd
(Szymon Duda)
May 9, 2023, 3:14pm
4
Another possible reason behind that error message is having no documents published of the custom type which it says is declared but unknown (i.e. 0 published documents of page
customType)
Hey, a similar issue happened to us today. We added a new customType and immediately the client functions stopped working because of the that error - Unknown type.
The solution was kind of unexpected - we needed to publish the first document of that type (even though we have the preview for drafts configured).
It seems like a bug to me. It should accept the valid customType value even if there are no documents of that type published. Otherwise any content editor can break the whole website if …
Thanks for the replies folks. The issue lay with the route resolver in this case. Something I seem to have issues getting my head around