Skip to content

Add support for "Node18" or "dom.fetch" in the "lib" configuration to support NodeJS Fetch API #53440

@yinzara

Description

@yinzara

NodeJS 18 now has the fetch API built in which includes support for all the normal Request/Response types supported by that API.

Right now if I attempt to use the tsconfig for NodeJS 18:

  "compilerOptions": {
    "target": "ES2022",
    "module": "Node16",
    "moduleResolution": "Node16",
    "lib": [
      "ES2022"
    ]
  }

If I attempt to use the fetch API in code (or any of the classes related to it like Request/Response), I get:

error TS2304: Cannot find name 'fetch'.

If I add dom to the lib element in the compilerOptions, it compiles successfully but then I have access to the entire dom library which I don't want.

Can we get a lib option of Node18 that adds all the classes related to the fetch APIs added in Node18? Or maybe just dom.fetch or something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    ExternalRelates to another program, environment, or user action which we cannot control.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions