Link resolver error while Next.js build

Hi. I am trying to Next.js app router build but it returns Link resolver error.

What is problem...

  • Returns Link resolver error on build
    • at type "homepage" and "recruit"

What I am trying...

  • pnpm run build with Next.js app router
  • Using slicemachine
  • page types
    • homepage: single
    • recruit: single
    • page: reusable
    • newsPost: reusable
  • custom types
    • category: reusable
    • navigation: reusable
  • All of type's article is published
  • pnpm run dev works correctly

It returns...

> next build

   β–² Next.js 14.0.4

 βœ“ Creating an optimized production build
 βœ“ Compiled successfully
 βœ“ Linting and checking validity of types
   Collecting page data  ..A [Error]: [Link resolver error] Unknown type
Declared type: homepage
Expected one of:
- page
- newsPost
- navigation
- category
[Link resolver error] Unknown type
Declared type: recruit
Expected one of:
- page
- newsPost
- navigation
- category
    at z.fetch (/Users/kazuto/develop/REPOSITORY_NAME/.next/server/chunks/3519.js:1:11561)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async z.get (/Users/kazuto/develop/REPOSITORY_NAME/.next/server/chunks/3519.js:1:4914)
    at async z.dangerouslyGetAll (/Users/kazuto/develop/REPOSITORY_NAME/.next/server/chunks/3519.js:1:5444)
    at async z.getAllByTag (/Users/kazuto/develop/REPOSITORY_NAME/.next/server/chunks/3519.js:1:6339)
    at async Object.b [as generateStaticParams] (/Users/kazuto/develop/REPOSITORY_NAME/.next/server/app/company/[uid]/page.js:1:7403)
    at async buildParams (/Users/kazuto/develop/REPOSITORY_NAME/node_modules/.pnpm/next@14.0.4_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/build/utils.js:987:36)
    at async /Users/kazuto/develop/REPOSITORY_NAME/node_modules/.pnpm/next@14.0.4_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/build/utils.js:1004:33
    at async /Users/kazuto/develop/REPOSITORY_NAME/node_modules/.pnpm/next@14.0.4_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/build/utils.js:1134:114
    at async Span.traceAsyncFn (/Users/kazuto/develop/REPOSITORY_NAME/node_modules/.pnpm/next@14.0.4_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/trace/trace.js:147:20) {
  url: 'https://REPOSITORY_NAME.cdn.prismic.io/api/v2/documents/search?q=%5B%5Bany%28document.tags%2C+%5B%22company%22%5D%29%5D%5D&pageSize=100&ref=ZWwc5BAAACMAyx8S&routes=%5B%7B%22type%22%3A%22newsPost%22%2C%22path%22%3A%22%2Fnews%2Farticle%2F%3Auid%22%7D%2C%7B%22type%22%3A%22page%22%2C%22path%22%3A%22%2F%3Auid%22%7D%2C%7B%22type%22%3A%22homepage%22%2C%22path%22%3A%22%2F%22%7D%2C%7B%22type%22%3A%22recruit%22%2C%22path%22%3A%22%2Frecruit%22%7D%5D',
  response: {
    type: 'Link resolver error',
    message: '[Link resolver error] Unknown type\n' +
      'Declared type: homepage\n' +
      'Expected one of:\n' +
      '- page\n' +
      '- newsPost\n' +
      '- navigation\n' +
      '- category\n' +
      '[Link resolver error] Unknown type\n' +
      'Declared type: recruit\n' +
      'Expected one of:\n' +
      '- page\n' +
      '- newsPost\n' +
      '- navigation\n' +
      '- category'
  }
}
{"type":"Link resolver error","message":"[Link resolver error] Unknown type\nDeclared type: homepage\nExpected one of:\n- page\n- newsPost\n- navigation\n- category\n[Link resolver error] Unknown type\nDeclared type: recruit\nExpected one of:\n- page\n- newsPost\n- navigation\n- category"}

src/prismicio.ts

  const routes: prismic.ClientConfig["routes"] = [
    {
      type: 'newsPost',
      path: "/news/article/:uid",
    },
    {
      type: "page",
      path: "/:uid",
    },
    {
      type: "homepage",
      path: "/",
    },
    {
      type: "recruit",
      path: "/recruit",
    },
  ];

app directory

src/app
β”œβ”€β”€ [uid]
β”‚   β”œβ”€β”€ page.tsx
β”‚   └── styles.module.css
β”œβ”€β”€ api
β”‚   β”œβ”€β”€ exit-preview
β”‚   β”‚   └── route.ts
β”‚   β”œβ”€β”€ preview
β”‚   β”‚   └── route.ts
β”‚   └── revalidate
β”‚       └── route.ts
β”œβ”€β”€ company
β”‚   β”œβ”€β”€ [uid]
β”‚   β”‚   └── page.tsx
β”‚   └── page.tsx
β”œβ”€β”€ favicon.ico
β”œβ”€β”€ globals.css
β”œβ”€β”€ layout.tsx
β”œβ”€β”€ news
β”‚   β”œβ”€β”€ [page]
β”‚   β”‚   └── page.tsx
β”‚   β”œβ”€β”€ article
β”‚   β”‚   └── [uid]
β”‚   β”‚       └── page.tsx
β”‚   β”œβ”€β”€ category
β”‚   β”‚   └── [category]
β”‚   β”‚       β”œβ”€β”€ [page]
β”‚   β”‚       β”‚   └── page.tsx
β”‚   β”‚       └── page.tsx
β”‚   └── page.tsx
β”œβ”€β”€ page.tsx
β”œβ”€β”€ recruit
β”‚   └── page.tsx
β”œβ”€β”€ services
β”‚   β”œβ”€β”€ [uid]
β”‚   β”‚   └── page.tsx
β”‚   └── page.tsx
└── slice-simulator
    └── page.tsx

Any idea what I am wrong?
Thank you.

Hi Kazuto,

Welcome to the community!

It's seems like you need to refresh your .next cache, you can manually delete the file on your local machine, if you're deployed on Vercel you can check the suggested fixes for the Next.js issue here:

I say this because your query isn't using the latest ref (ZZ-2sBEAACIAWozV) to get the latest content from Prismic. You can see it working here:
https://tees-consulting.cdn.prismic.io/api/v2/documents/search?q=[[any(document.tags%2C+["company"])]]&pageSize=100&ref=ZZ-2sBEAACIAWozV&routes=[{"type"%3A"newsPost"%2C"path"%3A"%2Fnews%2Farticle%2F%3Auid"}%2C{"type"%3A"page"%2C"path"%3A"%2F%3Auid"}%2C{"type"%3A"homepage"%2C"path"%3A"%2F"}%2C{"type"%3A"recruit"%2C"path"%3A"%2Frecruit"}]

Let me know if you need anything else.

Thanks.

1 Like

Hi phil.

Your solution was spot on. Thanks to your help, this issue has been resolved and everything is working properly!
Iam grateful for your prompt and excellent support!

1 Like