Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module not found: Error: Can't resolve 'ts-loader'

Following is my webpack.config.js

    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;

Its a typescript project.

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

Module not found: Error: Can't resolve 'ts-loader'

Not sure whats wrong.

I use ts-loader version 4.2.0

Typescript version 2.8.1

Kindly advice.

like image 871
MARKAND Bhatt Avatar asked Apr 10 '18 06:04

MARKAND Bhatt


People also ask

Can not Resolve TS-loader?

To solve the error "Module not found: Error: Can't resolve 'ts-loader'", make sure to install the ts-loader package by opening your terminal in your project's root directory and running the command npm install -D ts-loader typescript and restart your development server.

Does TS-loader use TSC?

ts-loader uses tsc , the TypeScript compiler, and relies on your tsconfig. json configuration.


1 Answers

make sure that you have ts-loader installed and added to the rules:

npm install -D ts-loader       

and

 module: {
    rules: [
      {test: /\.ts$/, exclude: /node_modules/, loader: 'ts-loader'}
    ]
  },
like image 192
David Dehghan Avatar answered Sep 17 '22 20:09

David Dehghan