No documents were returned

I just installed the latest next js and latest Prismic slice machine. The only code that I have on my page.jsx is below:

    import { createClient } from '@prismicio/client';

    export default async function Home() {
        const client = createClient();
        const page = await client.getByUID("page", "homepage");
     //even this doesn't work
     // const page = await client.getSingle('homepage');
    
        return (
            <main className="flex min-h-screen flex-col items-center justify-between p-24">
                <div>
                    <h1>Home Page</h1>
                </div>
            </main>
        );
    }

I have tried every single thing I can think of but I am always getting the error "No Document were returned", in addition in terminal I get the error

 GET https://undefined.cdn.prismic.io/api/v2 200 in 432ms (cache: MISS)

Any suggestions?

I think you’re doing what I did here

Hello @jismonthomas

Welcome to the Prismic community, and thanks for reaching out to us.

Does the solution provided by @frags work for you? I believe the same mistake is here. Let me know if it works for you; otherwise, I'll be happy to troubleshoot the issue.

Thanks,
Priyanka

Yes, it works for me the way I describe in the other thread.

Hi @Priyanka,

unfortunately that did not work for me, now its throwing an error saying module not found.

./src/app/page.js:1:0
Module not found: Can't resolve '@/prismicio'
> 1 | import { createClient } from '@/prismicio';

I only have one page in next js and prismic, not sure what causes this issue.

Thanks for the quick reply @frags, but that did not work for me actually! check my reply below.

Have you installed Slice Machine and done npx @slicemachine/init@latest - that's what creates the client in the root of your project.

yes, I have installed the slicemachine and its is running on my local machine!

And you don't have a prismicio.js|ts at the route of your project?

Yes, I do have the prosmicio.js file.

This is what I can see in that file, I haven't touched this

import * as prismic from "@prismicio/client";
import * as prismicNext from "@prismicio/next";
import config from "./slicemachine.config.json";

/**
 * The project's Prismic repository name.
 */
export const repositoryName = config.repositoryName;

/**
 * A list of Route Resolver objects that define how a document's `url` field
 * is resolved.
 *
 * {@link https://prismic.io/docs/route-resolver#route-resolver}
 *
 * @type {prismic.ClientConfig["routes"]}
 */
// TODO: Update the routes array to match your project's route structure.
const routes = [
  {
    type: "homepage",
    path: "/",
  },
  {
    type: "page",
    path: "/:uid",
  },
];

/**
 * Creates a Prismic client for the project's repository. The client is used to
 * query content from the Prismic API.
 *
 * @param {prismicNext.CreateClientConfig} config - Configuration for the Prismic client.
 */
export const createClient = (config = {}) => {
  const client = prismic.createClient(repositoryName, {
    routes,
    ...config,
  });

  prismicNext.enableAutoPreviews({
    client,
    previewData: config.previewData,
    req: config.req,
  });

  return client;
};

Hello @jismonthomas

Looking at your prismic.io js file, it seems you haven't updated the routes array to match your project's route structure. Can you share the repo name and the folder structure of the project?

Thanks,
Priyanka

Hello @jismonthomas

I have checked your project files and found multiple issues that you need to fix.

  1. To import prismicio in the about/page.js: file, the path should be:
    import { createClient } from "../../../prismicio"
    And on the page.js file, the path should be:
    import { createClient } from "../../prismicio"

That way, it will remove the no documents returned error.

  1. Next, you will get another error Error: [Link resolver error] Unknown type because your routes option should reflect the folder structure of your Next.js project. You need to correct that one. Please follow the define path article: Define Paths with Next.js - Documentation - Prismic

We have the simple starter project in Next js that will be helpful for you.

Thanks,
Priyanka

1 Like

Hi @Priyanka,

That worked like a charm, I did not realize that createClient was imported from 'prismicio.js' file, everything working perfect now. Thanks a lot for your help!.

note: I have deleted the threads with the names to my github & prismic repo.

@jismonthomas, I am glad that it worked for you. Feel free to reach out to us if you have any further questions.

1 Like