title: Unable to run script after I run it through webpack. (Error: unable to locate global object)
body: <p>I have a simple script.</p>
  
  <p><strong>script/src/index.js</strong></p>
  
  <pre><code>var fetch = require('node-fetch');
  
  console.log("working!")
  ...
  
  exports = { createClient, createDevice };
  </code></pre>
  
  <p><strong>script/webpack.config.js</strong></p>
  
  <pre><code>const path = require('path');
  
  module.exports = {
      entry: './src/index.js',
      mode: 'development',
      output: {
          filename: 'main.js',
          path: path.resolve(__dirname, 'dist')
      }
  };
  </code></pre>
  
  <p><strong>script/package.json</strong></p>
  
  <pre><code>{
      "name": "client",
      "version": "1.0.0",
      "private": true,
      "dependencies": {
          "node-fetch": "^2.3.0"
      },
      "devDependencies": {
          "webpack": "^4.26.0",
          "webpack-cli": "^3.1.2"
      },
      "scripts": {
          "build": "webpack"
      }
  }
  </code></pre>
  
  <p>Running the source code works fine</p>
  
  <pre><code>node script/src/index.js
  working!
  </code></pre>
  
  <p>Now I want to bundle the source code with the npm dependency so I run</p>
  
  <pre><code>npm run build
  </code></pre>
  
  <p>Then I try running the built code</p>
  
  <pre><code>node script/dist/main.js
  webpack:///./node_modules/node-fetch/browser.js?:11
      throw new Error('unable to locate global object');
      ^
  
  Error: unable to locate global object
      at getGlobal (webpack:///./node_modules/node-fetch/browser.js?:11:8)
      at eval (webpack:///./node_modules/node-fetch/browser.js?:14:14)
      at Object../node_modules/node-fetch/browser.js (/Users/xp025106/Dev/client-js/client/dist/main.js:97:1)
      at __webpack_require__ (/Users/xp025106/Dev/client-js/client/dist/main.js:20:30)
      at eval (webpack:///./src/index.js?:1:13)
      at Object../src/index.js (/Users/xp025106/Dev/client-js/client/dist/main.js:108:1)
      at __webpack_require__ (/Users/xp025106/Dev/client-js/client/dist/main.js:20:30)
      at /Users/xp025106/Dev/client-js/client/dist/main.js:84:18
      at Object.&lt;anonymous&gt; (/Users/xp025106/Dev/client-js/client/dist/main.js:87:10)
      at Module._compile (module.js:652:30)
  </code></pre>
  
  <p>Why can I not run the built code the same way I could run the source code?</p>