【发布时间】:2021-12-22 22:23:46
【问题描述】:
我正在尝试将我的打字稿文件导入webpack,当我在终端中运行tsc 时一切正常,但是当我尝试在ts-loader 中使用编译我的打字稿代码时,会显示这个奇怪的错误:
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),但它对我不起作用。
【问题讨论】:
标签: javascript typescript webpack