title: ts + webpack bundling for node cannot find module 'path'
body: <p>I know this has been asked before but I <em>cannot</em> get any accepted answer to work.</p>
  <p>My objective is to get each of my entry points to bundle as a single [entry].js for portability. Ideally I would like to have [entry].js and [entry].[modules/vendor].js but not necessary.</p>
  <p>What I have tried:</p>
  <ul>
  <li>Using <code>webpack-node-externals</code> with <code>allowlist</code>. Results in deep modules not being found</li>
  <li>Manual externals options <code>path: &quot;commonjs path&quot;</code>. Does not change result</li>
  <li><code>const {} = require('path')</code> instead of <code>import {} from 'path'</code>. Also doesn't change anything</li>
  <li>The configs below which I believe gets the closest result which is just that it cannot find built-ins.</li>
  </ul>
  <p><strong>tsconfig.json</strong></p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;compilerOptions&quot;: {
      &quot;module&quot;: &quot;commonjs&quot;,
      &quot;moduleResolution&quot;: &quot;node&quot;,
      &quot;esModuleInterop&quot;: true,
      &quot;outDir&quot;: &quot;launch&quot;,
      &quot;noImplicitAny&quot;: false,
      &quot;target&quot;: &quot;es5&quot;,
      &quot;allowJs&quot;: true,
      &quot;experimentalDecorators&quot;: true,
      &quot;emitDecoratorMetadata&quot;: true,
      &quot;allowSyntheticDefaultImports&quot;: true,
      &quot;sourceMap&quot;: true,
    },
    &quot;exclude&quot;: [
      &quot;__tests__&quot;,
      &quot;dist&quot;,
      &quot;launch&quot;
    ],
    &quot;include&quot;: [
      &quot;src/Auth&quot;,
      &quot;src/Gate&quot;,
      &quot;src/Patch&quot;,
      &quot;src/Account&quot;,
      &quot;src/Proxy&quot;,
    ]
  }
  </code></pre>
  <p><strong>webpack.config.js</strong></p>
  <pre class="lang-js prettyprint-override"><code>const path = require('path');
  module.exports = {
    target: 'node',
    mode: 'production',
    entry: {
      'gate': './src/Gate/index.ts',
      'patch': './src/Patch/index.ts',
      'auth': './src/Auth/index.ts',
      'account': './src/Account/index.ts',
      'proxy': './src/Proxy/index.ts',
    },
    stats: {warnings:false},
    module: {
      rules: [
        {
          test: /\.tsx?$/,
          use: 'ts-loader',
          exclude: /node_modules/
        },
      ]
    },
    resolve: {
      extensions: ['.tsx', '.ts', '.js']
    },
    optimization: {
      usedExports: true,
      chunkIds: 'natural',
      splitChunks: {
        // default splitChunks config
        chunks: 'async',
        minSize: 20000,
        minChunks: 1,
        maxAsyncRequests: 30,
        maxInitialRequests: 30,
        enforceSizeThreshold: 50000,
        cacheGroups: {
          defaultVendors: {
            test: /[\\/]node_modules[\\/]/,
            priority: -10,
            reuseExistingChunk: true,
          },
          default: {
            minChunks: 2,
            priority: -20,
            reuseExistingChunk: true,
          },
        },
      }
    }
  };
  </code></pre>