-
Notifications
You must be signed in to change notification settings - Fork 42
Open
Description
My API server is not accessible from my build server, so I get fetch errors when trying to render a component that has useSuspenseQuery
at build time. It works fine during SSR and client render, just not during the static prerender.
I should note this is from within app/
not pages/
, which is why I suspect a lot of the stuff I've tried isn't working.
If I have a component like
/app/page.tsx
and it imports a component like
'use client'
import { gql } from '@apollo/client';
import { useSuspenseQuery } from '@apollo/experimental-nextjs-app-support/ssr';
import { useState } from 'react';
// the docs seems to imply that these will stop server rendering
// like a dynamic slug will, but it does not work
export const dynamic = "force-dynamic";
export const revalidate = 0;
const query = gql`
query SomeQuery($substring: String!) {
/* whatever */
}
`
export default function SearchInput () {
const response: any = useSuspenseQuery(query);
const results = response?.data?.query
return (
<div>{JSON.stringify(data)}</div>
)
}
Then I get an error like this
$ npm run build
> [email protected] build
> next build
- info Creating an optimized production build
- info Compiled successfully
- info Linting and checking validity of types
- info Collecting page data
[ ] - info Generating static pages (0/4)ApolloError: fetch failed
... stacktrace omitted ...
graphQLErrors: [],
protocolErrors: [],
clientErrors: [],
networkError: TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11576:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
cause: Error: getaddrinfo ENOTFOUND some-internal-url
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:108:26)
at GetAddrInfoReqWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'some-internal-url'
}
},
extraInfo: undefined
}
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
ApolloError: fetch failed
... stacktrace omitted ....
- info Generating static pages (4/4)
> Export encountered errors on following paths:
/page: /
Metadata
Metadata
Assignees
Labels
No labels