ApolloError:网络错误:JSON中位置0处的tok en <意外

我在以下文件中收到错误:

import React from 'react';
import Head from 'next/head';
import App from 'Pages/_app';
import { initApolloClient } from 'Apollo/client';

const defaultHandler = () => ({ props: {} });

export default (Component) => (getServerSideProps = defaultHandler) => async (
  ctx,
) => {
  const apolloClient = (ctx.apolloClient = initApolloClient({
    res: ctx.res,
    req: ctx.req,
  }));

  const { props: pageProps } = await getServerSideProps(ctx);
  const props = {
    params: ctx.params || {},
    query: ctx.query,
    preview: ctx.preview || false,
    ...pageProps,
  };

  if (typeof window === 'undefined') {
    if (ctx.res && ctx.res.finished) {
      return { props };
    }

    try {
      const { getDataFromTree } = await import('@apollo/react-ssr');

      await getDataFromTree(
        <App
          Component={Component}
          pageProps={{
            ...props,
            apolloClient,
          }}
        />,
      );
    } catch (error) {
      console.error('Error while running `getDataFromTree`', error);
    }

    Head.rewind();
  }

  const apolloState = apolloClient.cache.extract();

  return {
    props: {
      ...props,
      apolloState,
    },
  };
};

I error message is: 'Error while running getDataFromTree ApolloError: Network error: Unexpected tok en < in JSON at position 0'

我也得到'graphQLErrors:[],   networkError:SyntaxError [ServerParseError]:意外的令牌<在JSON中,位于po 位置0 '

之后是404状态码。

这可能是什么原因?

评论