我试图将我的TypeScript文件导入webpack
,当我在终端中运行tsc
时一切都正常,但是当我尝试在ts-loader
编译我的TypeScript代码时,会显示一个奇怪的错误:
ERROR in ./src/Main.ts
Module build failed (from ./node_modules/ts-loader/index.js):
TypeError: loaderContext.getOptions is not a function
at getLoaderOptions (D:\Projects\Real\AviUI\node_modules\ts-loader\dist\index.js:91:41)
at Object.loader (D:\Projects\Real\AviUI\node_modules\ts-loader\dist\index.js:14:21)
webpack版本:4.43.0
,ts-loader版本:^9.2.3
,loader-utils版本:^1.4.0
webpack.config.js文件:
module.exports = {
entry: path.resolve(__dirname, './src/main.ts'),
module: {
rules: [
{
test: /\.ts$/,
include: [source_path],
loader: 'ts-loader',
exclude: /node_modules/,
}],
},
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
output: {
filename: 'avi_ui.js',
path: path.resolve(__dirname, 'dist')
},
externals: {
'jquery': '`jquery`',
'angular' : '`angular`'
},
mode: 'development'
};
注意:我尝试将我的typescript
编译器更新到最新版本(目前最新版本为4.3.3),但对我来说无效。
ts-loader
比升级webpack
更容易。 - Katzura