Module not found: Error: Can't resolve 'ts-loader' : <p>Following is my webpack.config.js</p>

<pre><code>    var webpack = require('webpack'),
  path = require('path'),
  yargs = require('yargs');

var libraryName = 'MyLib',
  plugins = [],
  outputFile;

if (yargs.argv.p) {
  plugins.push(new webpack.optimize.UglifyJsPlugin({
    minimize: true
  }));
  outputFile = libraryName + '.min.js';
} else {
  outputFile = libraryName + '.js';
}

var config = {
  entry: [
    __dirname + '/src/TestClass.ts'
  ],
  devtool: 'source-map',
  output: {
    path: path.join(__dirname, '/dist'),
    filename: outputFile,
    library: libraryName,
    libraryTarget: 'umd',
    umdNamedDefine: true
  },
  module: {
    rules: [{
      test: /\.tsx?$/,
      use: 'ts-loader', //Something wrong here
      exclude: /node_modules/
    }]
  },
  resolve: {
    modules: [__dirname],
    extensions: ['.ts', '.js', '.tsx']
  },
  plugins: plugins

      };

module.exports = config;
</code></pre>

<p>Its a typescript project.</p>

<p>When I run build and minify the typescript project using webpack version 4.5.0, I get following error</p>

<p><strong>Module not found: Error: Can't resolve 'ts-loader'</strong></p>

<p>Not sure whats wrong.</p>

<p>I use ts-loader version 4.2.0</p>

<p>Typescript version 2.8.1</p>

<p>Kindly advice.</p>
