From 51627fede9abcac4ac4a85349437e5e18a92a5f3 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 3c27c81cf..8c4a29a67 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)) { - urlStr = new URL(urlStr).toString() + urlStr = new whatwgUrl.URL(urlStr).toString() } // Fallback to old implementation for arbitrary URLs diff --git a/test/test.js b/test/test.js index 9568489e3..57224fdb9 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);