我有以下 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:\Users\Koder\Desktop\programingLS\Education\Topics\Web\Lessons\TypeScript\node_modules\html-webpack-plugin\index.js(16,19)
TS2306: File 'C:\Users\Koder\Desktop\programingLS\Education\Topics\Web\Lessons\TypeScript\node_modules\lodash\lodash.js' is not a module.
套餐: “开发依赖项”:{ "html-webpack-plugin": "^4.3.0", "lodash": "^4.17.20", "ts-loader": "^8.0.2", “ typescript ”:“^3.9.7”, "webpack": "^4.44.1", “webpack-cli”:“^3.3.12” }
最佳答案
我使用以下命令修复了问题:
npm install --save @types/html-webpack-plugin
关于typescript - 为什么 typescript loader 会导致 html webpack 插件出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63488241/