diff --git a/fetch.browser.js b/fetch.browser.js index 3c23987..2357f10 100644 --- a/fetch.browser.js +++ b/fetch.browser.js @@ -1 +1 @@ -module.exports = fetch.bind(globalThis) +module.exports = (i, ...r) => globalThis.fetch(i, ...r) diff --git a/fetch.js b/fetch.js index 6a995a1..3ec97ff 100644 --- a/fetch.js +++ b/fetch.js @@ -9,12 +9,18 @@ if (typeof process !== 'undefined' && process) { // Node.js or Electron with Node.js integration if (process.type === 'renderer' || process.type === 'worker') { // Electron renderer with Node.js integration - module.exports = fetch + module.exports = (i, ...r) => globalThis.fetch(i, ...r) } else { // Node.js or Electron browser process - module.exports = typeof fetch === 'undefined' ? require('node-fetch') : fetch.bind(globalThis) + if (typeof fetch === 'undefined') { + // Fall back to node-fetch + module.exports = require('node-fetch') + } else { + // Prefer Node.js fetch if exists + module.exports = (i, ...r) => globalThis.fetch(i, ...r) + } } } else { // Browser or Electron without Node.js integration - module.exports = fetch + module.exports = (i, ...r) => globalThis.fetch(i, ...r) } diff --git a/fetch.native.js b/fetch.native.js index 0921582..9afa8b1 100644 --- a/fetch.native.js +++ b/fetch.native.js @@ -1,3 +1,9 @@ 'use strict' -module.exports = typeof fetch === 'undefined' ? require('node-fetch') : fetch.bind(globalThis) +if (typeof fetch === 'undefined') { + // Fall back to node-fetch + module.exports = require('node-fetch') +} else { + // Prefer native / Node.js fetch if exists + module.exports = (i, ...r) => globalThis.fetch(i, ...r) +} diff --git a/fetchival.browser.js b/fetchival.browser.js index d0e1b5e..326ee22 100644 --- a/fetchival.browser.js +++ b/fetchival.browser.js @@ -1,5 +1,5 @@ const createFetchival = require('./create-fetchival') module.exports = createFetchival({ - fetch: typeof fetch === 'undefined' ? null : fetch.bind(globalThis), + fetch: typeof fetch === 'undefined' ? null : (i, ...r) => globalThis.fetch(i, ...r), })