Skip to content

Agent did not support on node latest LTS (v18.14.2) #215

@pidanmeng

Description

@pidanmeng

Update

it seems like a bug of node


Environment

ofetch: v1.0.1
node:v18.14.2

Reproduction

here is a minimum recurrence demo

import { getProxySettings } from "get-proxy-settings";
import { ofetch } from "ofetch/node";
import httpAgent from 'http-proxy-agent'
import httpsAgent from 'https-proxy-agent'

let agent
await (async function setSystemProxy() {
  const { http, https } = (await getProxySettings()) || {}
  function agentGenerator(ProxySetting) {
    const { protocol, host, port } = ProxySetting
    const agentUrl = `${protocol}://${host}:${port}`
    if (protocol === 'http') {
      return new httpAgent(agentUrl)
    }
    if (protocol === 'https') {
      return new httpsAgent(agentUrl)
    }
    return false
  }
  if (http) {
    agent = agentGenerator(http)
  }
  if (https) {
    agent = agentGenerator(https)
  }
})().then(async () => {
  const response = await ofetch.raw('https://google.com', { agent })
})

Describe the bug

Nodejs has supported fetch api since v17.5.0

This caused current issue:

export const fetch = globalThis.fetch || createNodeFetch();

I'm going to submit a PR to fix this bug!

Additional context

No response

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationnode

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions