@@ -2,7 +2,8 @@ import { randomBytes, createHash } from 'node:crypto';
22import { Readable } from 'node:stream' ;
33import { performance } from 'node:perf_hooks' ;
44import { ReadableStream , TransformStream } from 'node:stream/web' ;
5- import { Blob } from 'node:buffer' ;
5+ import { Blob , File } from 'node:buffer' ;
6+ import { toUSVString } from 'node:util' ;
67import type { FixJSONCtlChars } from './Request.js' ;
78import { SocketInfo } from './Response.js' ;
89import symbols from './symbols.js' ;
@@ -231,6 +232,37 @@ export function patchForNode16() {
231232 // @ts -ignore
232233 global . DOMException = getDOMExceptionClass ( ) ;
233234 }
235+ // multi undici version in node version less than 20 https://github.com/nodejs/undici/issues/4374
236+ if ( typeof globalThis . File === 'undefined' ) {
237+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
238+ // @ts -ignore
239+ globalThis . File = File ;
240+ }
241+
242+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
243+ // @ts -ignore
244+ if ( String . prototype . toWellFormed === undefined ) {
245+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
246+ // @ts -ignore
247+ String . prototype . toWellFormed = function ( ) {
248+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
249+ // @ts -ignore
250+ return toUSVString ( this ) ;
251+ }
252+ }
253+
254+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
255+ // @ts -ignore
256+ if ( String . prototype . isWellFormed === undefined ) {
257+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
258+ // @ts -ignore
259+ String . prototype . isWellFormed = function ( ) {
260+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
261+ // @ts -ignore
262+ return toUSVString ( this ) === this ;
263+ }
264+ }
265+
234266}
235267
236268// https://github.com/jimmywarting/node-domexception/blob/main/index.js
0 commit comments