Vigia

Nâng cấp node-fetch từ 2.x lên 3.x

So sánh API công khai của node-fetch 2.7.0 và 3.3.2, được tính tự động từ kiểu TypeScript. Chữ ký thay đổi là thay đổi có thể không tương thích, không phải điều chắc chắn.

Tóm tắt

Đường dẫn import bị xóa1
Export bị xóa6
Chữ ký thay đổi5
Thành viên lớp hoặc interface bị xóa19
Thành viên lớp hoặc interface thay đổi14
Mới bị ngừng hỗ trợ3
Thay đổi yêu cầu (engines, phụ thuộc peer)2
Export mới7

Đường dẫn import bị xóa

Đường dẫn import bị xóa
node-fetch/externals

Export bị xóa

importexportkindTrước
node-fetchHeaderInittypeHeaders | string[][] | { [key: string]: string | string[]; }
node-fetchRequestModetype"same-origin" | "cors" | "no-cors"
node-fetchRequestCachetype"default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload"
node-fetchResponseTypetype"error" | "default" | "cors" | "basic" | "opaque" | "opaqueredirect"
node-fetchRequestContexttype"object" | "audio" | "beacon" | "cspreport" | "download" | "embed" | "eventsource" | "favicon" | "fetch" | "font" | "form" | "frame" | "hyperlink" | "iframe" | "image" | "imageset" | "import" | "internal" | "location" | "manifest" | "ping" | "plugin" | "prefetch" | "script" | "serviceworker" | "sharedworker" | "style" | "subresource" | "track" | "video" | "worker" | "xmlhttprequest" | "xslt"
node-fetchRequestCredentialstype"omit" | "include" | "same-origin"

Chữ ký thay đổi

exportTrướcSau
node-fetch · Blobclassany
node-fetch · Bodyclassinterface
node-fetch · default(url: RequestInfo, init?: RequestInit | undefined): Promise<Response>(url: URL | RequestInfo, init?: RequestInit | undefined): Promise<Response>
node-fetch · HeadersInitHeaders | string[][] | { [key: string]: string | string[]; }Headers | Record<string, string> | Iterable<readonly [string, string]> | Iterable<Iterable<string>>
node-fetch · RequestInfostring | Request | URLLikestring | Request

Thành viên lớp hoặc interface bị xóa

memberimportTrước
Body.timeoutnode-fetchnumber
Body.textConvertednode-fetch(): Promise<string>
Request.portnode-fetchnumber | undefined
Request.agentnode-fetchany
Request.follownode-fetchnumber
Request.contextnode-fetchRequestContext
Request.counternode-fetchnumber
Request.timeoutnode-fetchnumber
Request.compressnode-fetchboolean
Request.hostnamenode-fetchstring
Request.protocolnode-fetchstring
Request.textConvertednode-fetch(): Promise<string>
Response.timeoutnode-fetchnumber
Response.textConvertednode-fetch(): Promise<string>
RequestInit.timeoutnode-fetchnumber | undefined
ResponseInit.urlnode-fetchstring | undefined
ResponseInit.sizenode-fetchnumber | undefined
ResponseInit.counternode-fetchnumber | undefined
ResponseInit.timeoutnode-fetchnumber | undefined

Thành viên lớp hoặc interface thay đổi

memberTrướcSau
Body.bodyNodeJS.ReadableStreamany
Body.json(): Promise<any>(): Promise<unknown>
Body.constructor(body?: any, opts?: { size?: number | undefined; timeout?: number | undefined; } | undefined): Body
Headers.raw(): { [k: string]: string[]; }(): Record<string, string[]>
Headers.forEach(callback: (value: string, name: string) => void): void(callbackfn: (value: string, key: string, parent: Headers) => void, thisArg?: any): void
Request.bodyNodeJS.ReadableStreamany
Request.json(): Promise<any>(): Promise<unknown>
Request.constructor(input: RequestInfo, init?: RequestInit | undefined): Request(input: URL | RequestInfo, init?: RequestInit | undefined): Request
Response.bodyNodeJS.ReadableStreamany
Response.json(): Promise<any>(): Promise<unknown>
Response.static redirect(url: string, status: number): Response(url: string, status?: number | undefined): Response
AbortError.type"aborted"string
AbortError.constructor(message: string): AbortError(message?: string | undefined): AbortError | (message?: string | undefined, options?: ErrorOptions | undefined): AbortError
FetchError.constructor(message: string, type: string, systemError?: SystemError | undefined): FetchError(message: string, type: string, systemError?: Record<string, unknown> | undefined): FetchError

Mới bị ngừng hỗ trợ

export@deprecated
node-fetch · Body.bufferUse `body.arrayBuffer()` instead.
node-fetch · Request.bufferUse `body.arrayBuffer()` instead.
node-fetch · Response.bufferUse `body.arrayBuffer()` instead.

Thay đổi yêu cầu (engines, phụ thuộc peer)

TrướcSau
engines.node4.x || >=6.0.0^12.20.0 || ^14.13.1 || >=16.0.0
peerDependencies.encoding^0.1.0—
Export mới (7)
importexportkind
node-fetchFilevariable
node-fetchFormDatavariable
node-fetchblobFromvariable
node-fetchfileFromvariable
node-fetchblobFromSyncvariable
node-fetchfileFromSyncvariable
node-fetchReferrerPolicytype

Câu hỏi thường gặp

Nâng cấp node-fetch từ 2 lên 3 có những thay đổi không tương thích nào?

Giữa node-fetch 2.7.0 và 3.3.2, Vigia tìm thấy 6 export bị xóa, 5 chữ ký thay đổi và 33 thành viên lớp hoặc interface bị xóa hay thay đổi.

Những gì bị ngừng hỗ trợ trong node-fetch 3?

3 export hoặc thành viên mới bị đánh dấu ngừng hỗ trợ trong node-fetch 3.3.2.

Dành cho tác tử

GET https://vigia.coredls.cloud/v1/packages/npm/node-fetch/upgrade?from=2.7.0&to=3.3.2