typescript 找不到模块:错误:无法解析“ts-loader”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49747088/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:20:55  来源:igfitidea点击:

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

typescriptwebpackts-loader

提问by MARKAND Bhatt

Following is my webpack.config.js

以下是我的 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

当我使用 webpack 4.5.0 版运行构建和缩小打字稿项目时,出现以下错误

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

找不到模块:错误:无法解析“ts-loader”

Not sure whats wrong.

不知道出了什么问题。

I use ts-loader version 4.2.0

我使用 ts-loader 版本 4.2.0

Typescript version 2.8.1

打字稿版本 2.8.1

Kindly advice.

友善的建议。

回答by David Dehghan

I just installed ts-loader and the problem went away:

我刚刚安装了 ts-loader,问题就消失了:

npm install -D ts-loader       

and

 module: {
    rules: [
      {test: /\.ts$/, exclude: /node_modules/, loader: 'ts-loader'}
    ]
  },