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

2

32

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.

Drawtube answered 10/4, 2018 at 6:44 Comment(3)
You have ts-loader installed ? in your package.json dev dependencies ? My line look the same : { test: /\.ts$/, use: [{ loader: 'ts-loader', options: { silent: true } }, 'angular-router-loader'] }, Im using ts-loader 2.2.2, You are using a pretty advanced typescript versionAlgy
yeah. I have got ts-loader installed. Its in package.json under dev dependencies.Drawtube
Have you tried { loader: 'ts-loader' } instead of 'ts-loader'Algy
A
48

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'}
    ]
  },

Update: It seems that people have problem with ts-loader installation. using "npm ci" or deleting your node_modules folder is good start. I am not aware of anything specific with this package that prevents it from being installed npm.

Agonist answered 28/7, 2018 at 8:17 Comment(2)
This answer does not explain why npm is not installing ts-loader when it is present in package.json.Kippar
in my case I just had to restart VSSunil
T
1

Same here, I already had ts-loader listed in my package.json, but for some reason it was not installed anymore at some point.

For me, what worked is I forced reinstall of all modules and it appeared and worked again.

npm i -force

or

yarn install --force
Taegu answered 1/4, 2022 at 6:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.