title: How to create umd bundle with fetch polyfill, rollup and typescript?
body: <p>I'm trying to bundle a library with rollup.</p>
  <p>In this library i'm making http requests.
  I would like to use <code>fetch</code> and have a polyfill be used when the code is run on node.
  I can not get the configuration right.
  Either it works on node but not in the browser, or the opposite.</p>
  <p>This is how my config file looks like:</p>
  <pre class="lang-js prettyprint-override"><code> module.exports = [{
      input: 'src/mylibrary.ts',
      output: {
        name: LIB_NAME,
        file: getOutputFileName(
          resolve(ROOT, pkg.browser),
          env === 'production'
        ),
        format: 'umd',
        globals: {
          fetch: 'cross-fetch',
        },
      },
      plugins: [
       typescript({
        useTsconfigDeclarationDir: true,
        tsconfigOverride: {
          allowJs: false,
          includes: ['src'],
          exclude: ['tests', 'examples', '*.js', 'scripts'],
          esModuleInterop: true,
        },
       }),
        nodeResolve({
          mainFields: ['jsnext', 'main'],
          preferBuiltins: true,
          browser: true,
        }),
        commonjs({
          include: ['node_modules/**'],
        }),
        json(),
        env === 'production' ? terser() : {}, // will minify the file in production mode
      ],
    }]
  
  </code></pre>
  <p>This is the how I import fetch in my code :</p>
  <pre class="lang-js prettyprint-override"><code>import 'cross-fetch/polyfill'
  </code></pre>
  <p>In browser it works great ✅</p>
  <p>In node I have the following error ❌:</p>
  <pre class="lang-sh prettyprint-override"><code>  throw new Error('unable to locate global object');
          ^
  
  Error: unable to locate global object
  </code></pre>
  <p>When I look into the bundled umd it comes from here:</p>
  <pre class="lang-js prettyprint-override"><code>var getGlobal = function () {
          // the only reliable means to get the global object is
          // `Function('return this')()`
          // However, this causes CSP violations in Chrome apps.
          if (typeof self !== 'undefined') { return self; }
          if (typeof window !== 'undefined') { return window; }
          if (typeof global !== 'undefined') { return global; }
          throw new Error('unable to locate global object');
      };
  </code></pre>
  <p>Any idea what might be the problem ?</p>