Введите «Агент | ((parsedUrl: URL) => Агент) | undefined 'не может быть назначен типу' Агент | неопределенный'

Я получаю эту ошибку во время команды сборки next.js commerce.

      Type error: Argument of type '{ method: string; headers: { 'Content-Type': string; } | { 'Content-Type': string; } | { 'Content-Type': string; length: number; toString(): string; toLocaleString(): string; pop(): string[] | undefined; ... 29 more ...; [Symbol.unscopables](): { ...; }; } | { ...; }; ... 7 more ...; timeout?: number | undefined; }' is not assignable to parameter of type 'FetchOptions'.
  Type '{ method: string; headers: { 'Content-Type': string; } | { 'Content-Type': string; } | { 'Content-Type': string; length: number; toString(): string; toLocaleString(): string; pop(): string[] | undefined; ... 29 more ...; [Symbol.unscopables](): { ...; }; } | { ...; }; ... 7 more ...; timeout?: number | undefined; }' is not assignable to type '{ agent?: Agent | undefined; retry?: RetryOptions | undefined; }'.
    Types of property 'agent' are incompatible.
      Type 'Agent | ((parsedUrl: URL) => Agent) | undefined' is not assignable to type 'Agent | undefined'.

   8 |   async (query: string, { variables, preview } = {}, fetchOptions) => {
   9 |     const config = getConfig()
> 10 |     const res = await fetch(config.commerceUrl, {
     |                                                 ^
  11 |       ...fetchOptions,
  12 |       method: 'POST',
  13 |       headers: {

Файл, на который он жалуется, довольно прост:

      import { FetcherError } from '@commerce/utils/errors'
import type { GraphQLFetcher } from '@commerce/api'
import type { LocalConfig } from '../index'
import fetch from './fetch'

const fetchGraphqlApi: (getConfig: () => LocalConfig) => GraphQLFetcher =
  (getConfig) =>
  async (query: string, { variables, preview } = {}, fetchOptions) => {
    const config = getConfig()
    const res = await fetch(config.commerceUrl, {
      ...fetchOptions,
      method: 'POST',
      headers: {
        ...fetchOptions?.headers,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        query,
        variables,
      }),
    })

    const json = await res.json()
    if (json.errors) {
      throw new FetcherError({
        errors: json.errors ?? [{ message: 'Failed to fetch for API' }],
        status: res.status,
      })
    }

    return { data: json.data, res }
  }

export default fetchGraphqlApi

В этом файле очень мало определений типов, но, очевидно, он выводит множество, и я действительно не уверен, как его отлаживать. Я обновился до последней версии node npm и typescript.

Нужно ли мне возвращаться и искать все места, где это вызывается, чтобы увидеть, где произошла ошибка при наборе текста?

Похоже, это может быть связано с некоторыми проблемами с "https-proxy-agentмодуль, так как я обнаружил несколько связанных ошибок. https://github.com/TooTallNate/node-https-proxy-agent/issues/27 https://github.com/TooTallNate/node-https-proxy-agent/issues/114

Но я не понимаю, как любое из этих решений может исправить этот код.

РЕДАКТИРОВАТЬ:./fetch.js

      import zeitFetch from '@vercel/fetch'
export default zeitFetch()

0 ответов

Другие вопросы по тегам