title: Typescript + Webpack library generates "ReferenceError: self is not defined"
body: <p>I'm building a TS library bundled with Webpack 5.3.2. I then try to load the output bundle, <code>dist/scalextric.js</code>, into a <code>node.js</code> script:</p>
  <pre><code>node -e 'console.dir(Object.keys(require(&quot;./dist/scalextric.js&quot;)));'
  </code></pre>
  <p>I get:</p>
  <pre><code>ReferenceError: self is not defined
      at Object.&lt;anonymous&gt; (/media/kratib/Data/src/infojunkie/scalextric/dist/scalextric.js:2:215)
      at Module._compile (internal/modules/cjs/loader.js:1063:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
      at Module.load (internal/modules/cjs/loader.js:928:32)
      at Function.Module._load (internal/modules/cjs/loader.js:769:14)
      at Module.require (internal/modules/cjs/loader.js:952:19)
      at require (internal/modules/cjs/helpers.js:88:18)
      at [eval]:1:25
      at Script.runInThisContext (vm.js:132:18)
      at Object.runInThisContext (vm.js:309:38)
  </code></pre>
  <p>I need help fixing this error. Here are my various configs:</p>
  <ul>
  <li><code>webpack.config.js</code>:</li>
  </ul>
  <pre><code>const path = require('path');
  
  module.exports = {
    entry: './src/index.ts',
    devtool: 'inline-source-map',
    module: {
      rules: [
        {
          test: /\.tsx?$/,
          use: 'ts-loader',
          exclude: /node_modules/,
        },
      ],
    },
    resolve: {
      extensions: [ '.tsx', '.ts', '.js' ],
    },
    output: {
      filename: 'scalextric.js',
      library: 'Scalextric',
      libraryTarget: 'umd',
      path: path.resolve(__dirname, 'dist'),
      umdNamedDefine: true,
    },
  };
  </code></pre>
  <ul>
  <li><code>tsconfig.json</code>:</li>
  </ul>
  <pre><code>{
    &quot;compilerOptions&quot;: {
      &quot;module&quot;: &quot;commonjs&quot;,
      &quot;lib&quot;: [&quot;dom&quot;, &quot;esnext.asynciterable&quot;],
      &quot;target&quot;: &quot;es6&quot;,
      &quot;moduleResolution&quot;: &quot;node&quot;,
      &quot;outDir&quot;: &quot;./dist&quot;,
      &quot;sourceMap&quot;: true,
      &quot;declaration&quot;: true,
      &quot;importHelpers&quot;: true
    },
    &quot;include&quot;: [
      &quot;src&quot;
    ]
  }
  </code></pre>
  <ul>
  <li><code>index.ts</code>:</li>
  </ul>
  <pre><code>export * from './Tuning';
  export * from './TuningNotation';
  export * from './Interval';
  </code></pre>
  <p>Any obvious mistake I am making? <a href="https://github.com/infojunkie/scalextric" rel="noreferrer">Here's the full code</a>.</p>