为什么typescript加载程序会导致html webpack插件出错



我有以下的webpack配置

const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
context: path.resolve(__dirname, "src"),
entry: "./index.ts",
module: {
rules: [
{
test: /.tsx?$/,
use: "ts-loader",
exclude: [/node_modules/],
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
output: {
filename: "bundle.js",
path: path.resolve(__dirname, "dist"),
},
plugins: [
new HtmlWebpackPlugin({
template: "index.html",
}),
],
};

然而,每次运行webpack时,我都会收到这些错误,typescript文件会成功编译

[tsl] ERROR in C:UsersKoderDesktopprogramingLSEducationTopicsWebLessonsTypeScriptnode_moduleshtml-webpack-pluginindex.js(16,19)
TS2306: File 'C:UsersKoderDesktopprogramingLSEducationTopicsWebLessonsTypeScriptnode_moduleslodashlodash.js' is not a module.

软件包:"devDependencies":{"html webpack插件":"4.3.0";,"lodash":"4.17.20〃;,"ts加载器":"8.0.2〃;,"typescript":"3.9.7";,"webpack":"4.44.1〃;,"webpack-cli":"3.3.12";}

我用以下命令修复了问题:

npm install --save @types/html-webpack-plugin 

最新更新