TypeError: value.subscribe is not a function

I’m trying to use BatchHttpLink to batch requests from apollo on a nextjs application using below config:

import fetch from 'isomorphic-unfetch';
import { ApolloProvider, ApolloClient, ApolloLink, from } from '@apollo/client'; 
import { onError } from '@apollo/client/link/error'; 
import { BatchHttpLink } from '@apollo/client/link/batch-http';

const batchHttpLink = new BatchHttpLink({
    uri: process.env.GRAPHQL_URL,
    batchMax: 5,
    batchInterval: 20,
    credentials: 'same-origin',
    fetch
});

  /**
   * to parse batch call response
   * See more https://spectrum.chat/apollo/apollo-client/batchhttplink-not-working-with-usequery-react-hooks~3eeb6635-c5a8-4b8a-a2fd-3b7fbebc5816
   */
  const parseBatchResponseMiddleware = new ApolloLink((operation, forward) =>
    forward(operation).map((data: any) => data.payload)
  );

  const errorLink = onError(({ graphQLErrors, networkError, forward, operation }) => {
    if (graphQLErrors) {
      console.warn(graphQLErrors);
    }
    if (networkError) {
      console.warn(networkError);
    }
    forward(operation);
  });

  return new ApolloClient({
    ssrMode: typeof window === 'undefined',
    link: from([parseBatchResponseMiddleware, errorLink, authLink.concat(batchHttpLink)]),
    cache: new InMemoryCache({
      possibleTypes: introspectionToPossibleTypes(introspectionQueryResultData)
    })
  });

I added parseBatchResponseMiddleware to parse the batch response. When I run app on development mode everything seems correct but as soon as I build app on prod environment it returns 500-internal server error:

TypeError: value.subscribe is not a function at Object.complete
(/.../node_modules/@apollo/client/utilities/observables/Concast.js:57:43) at Concast.start
(/.../node_modules/@apollo/client/utilities/observables/Concast.js:83:23) at new Concast
(/.../node_modules/@apollo/client/utilities/observables/Concast.js:75:19) at QueryManager.getObservableFromLink
(/.../node_modules/@apollo/client/core/QueryManager.js:551:35) at QueryManager.getResultsFromLink
(/.../node_modules/@apollo/client/core/QueryManager.js:590:30) at resultsFromLink
(/.../node_modules/@apollo/client/core/QueryManager.js:755:26) at QueryManager.fetchQueryByPolicy
(/.../node_modules/@apollo/client/core/QueryManager.js:782:21) at fromVariables
(/.../node_modules/@apollo/client/core/QueryManager.js:638:26) at QueryManager.fetchQueryObservable
(/.../node_modules/@apollo/client/core/QueryManager.js:645:15) at QueryManager.fetchQuery
(/.../node_modules/@apollo/client/core/QueryManager.js:260:21) at QueryManager.query
(/.../node_modules/@apollo/client/core/QueryManager.js:345:21) at ApolloClient.query
(/.../node_modules/@apollo/client/core/ApolloClient.js:133:34) at Function.Z.t.getInitialProps
(/.../src/.next/server/pages/_app.js:158:151526) at Function.B.r.getInitialProps (/.../src/.next/server/pages/_app.js:158:147992)

Any ideas to solve this issue is highly appreciated.