typescript - 为什么 typescript loader 会导致 html webpack 插件出错?

标签 typescript 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:\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/

相关文章:

reactjs - 这是TS的bug吗? (插值的 esliteral 不被视为字符串类型)

angular - 如何使用 Angular 2 中的特定 keyCode 测试 Jasmine 中的按键事件

javascript - 在 React 中重置子组件中的选项卡

TypeScript 0.8.2 在保存时编译 AMD 模块

node.js - 实体元数据未找到 : Node. js TypeScript TypeORM

laravel - 控制 webpack 编译进度输出 - Laravel Mix/Envoy

webpack - 通过插件复制源时使用 terser webpack 插件而不是 uglify

javascript - Webpack ES6 modules 使用索引文件时的循环依赖

node.js - gulp 未在 Docker ubuntu 上运行

javascript - webpack 如何解决全局污染?