From 14e1f396c632c82e0b1a0066e906a798a962fe06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Tue, 21 Sep 2021 16:44:04 +0200 Subject: [PATCH] fix: import whatwg-url in a way compatible with ESM Node --- src/request.js | 4 ++-- test/test.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/request.js b/src/request.js index 6fa8e77b6..53a968911 100644 --- a/src/request.js +++ b/src/request.js @@ -9,7 +9,7 @@ import Url from 'url'; import Stream from 'stream'; -import {URL} from 'whatwg-url'; +import whatwgUrl from 'whatwg-url'; import Headers, { exportNodeCompatibleHeaders } from './headers.js'; import Body, { clone, extractContentType, getTotalBytes } from './body'; @@ -33,7 +33,7 @@ function parseURL(urlStr) { Absolute URL: https://tools.ietf.org/html/rfc3986#section-4.3 */ if (/^[a-zA-Z][a-zA-Z\d+\-.]*:/.exec(urlStr)) { - const url = new URL(urlStr); + const url = new whatwgUrl.URL(urlStr); return { path: url.pathname, diff --git a/test/test.js b/test/test.js index 9220cbd4a..b1c80018a 100644 --- a/test/test.js +++ b/test/test.js @@ -9,7 +9,7 @@ import resumer from 'resumer'; import FormData from 'form-data'; import stringToArrayBuffer from 'string-to-arraybuffer'; import URLSearchParams_Polyfill from '@ungap/url-search-params'; -import { URL } from 'whatwg-url'; +import whatwgUrl from 'whatwg-url'; import { AbortController } from 'abortcontroller-polyfill/dist/abortcontroller'; import AbortController2 from 'abort-controller'; @@ -1812,7 +1812,7 @@ describe('node-fetch', () => { it('should support fetch with WHATWG URL object', function() { const url = `${base}hello`; - const urlObj = new URL(url); + const urlObj = new whatwgUrl.URL(url); const req = new Request(urlObj); return fetch(req).then(res => { expect(res.url).to.equal(url);