FredKSchott / rollup-plugin-polyfill-node

A modern Node.js polyfill for your Rollup bundle.
Other
178 stars 57 forks source link

Failed to check node env due to polyfill. #45

Open ZhUyU1997 opened 2 years ago

ZhUyU1997 commented 2 years ago

I am using axios on node.js (4.x). It has the logic that checks if node env. It failed because of polyfill.

function getDefaultAdapter() {
  var adapter;

  if (typeof XMLHttpRequest !== 'undefined') {
    // For browsers use XHR adapter
    adapter = xhr;
  } else if (typeof browser$1 !== 'undefined' && Object.prototype.toString.call(browser$1) === '[object process]') {
    // For node use HTTP adapter
    adapter = http_1;
  }
  console.log("getDefaultAdapter", adapter,)
  return adapter;
}

browser$1 is defined by polyfills/process-es6.js. But I think we should not inject it if using node.js.

var browser$1 = {
  nextTick: nextTick,
  title: title,
  browser: browser,
  env: env,
  argv: argv,
  version: version,
  versions: versions,
  on: on,
  addListener: addListener,
  once: once,
  off: off,
  removeListener: removeListener,
  removeAllListeners: removeAllListeners,
  emit: emit,
  binding: binding,
  cwd: cwd,
  chdir: chdir,
  umask: umask,
  hrtime: hrtime,
  platform: platform,
  release: release,
  config: config,
  uptime: uptime
};