diff --git a/PDFMergerBase.js b/PDFMergerBase.js index 6285dfa..9df364b 100644 --- a/PDFMergerBase.js +++ b/PDFMergerBase.js @@ -162,6 +162,9 @@ export default class PDFMergerBase { // see https://developer.mozilla.org/en-US/docs/Web/API/URL if (input instanceof URL) { + if (typeof fetch === 'undefined') { + throw new Error('fetch is not defined. You need to use a polyfill for this to work in Node.js.') + } const res = await fetch(input) const aBuffer = await res.arrayBuffer() return new Uint8Array(aBuffer) diff --git a/test/PDFMerger.test.js b/test/PDFMerger.test.js index 91ef80d..ccb7262 100644 --- a/test/PDFMerger.test.js +++ b/test/PDFMerger.test.js @@ -121,7 +121,8 @@ describe('PDFMerger', () => { expect(diff).toBeFalsy() }) - test('provide input as URL', async () => { + const testIfFetch = typeof fetch !== 'undefined' ? test : test.skip + testIfFetch('provide input as URL', async () => { const merger = new PDFMerger() const TestfileAURL = new URL('https://raw.githubusercontent.com/nbesli/pdf-merger-js/master/test/fixtures/Testfile_A.pdf') expect(TestfileAURL).toBeInstanceOf(URL)