【问题标题】:error Unable to resolve path to module 'html-webpack-plugin' import/no-unresolved错误无法解析模块 \'html-webpack-plugin\' import/no-unresolved 的路径
【发布时间】:2023-01-17 03:29:40
【问题描述】:

我收到这个错误

/home/runner/work/toDoList/toDoList/webpack.config.js
  2:35  error  Unable to resolve path to module 'html-webpack-plugin'  import/no-unresolved

在由 GitHub 操作运行的我的 linters 上。

我在本地运行 eslint 时没有收到此错误;这只发生在 GitHub 操作中。这些解决方案对我不起作用。

这是我的webpack.config.js

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  entry: './src/index.js',
  devtool: 'inline-source-map',
  devServer: {
    static: './dist',
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './src/index.html',
    }),
  ],
  output: {
    filename: 'main.js',
    path: path.resolve(__dirname, 'dist'),
  },
  module: {
    rules: [
      {
        test: /\.css$/i,
        use: ['style-loader', 'css-loader'],
      },
    ],
  },
};

还有我的.eslintrc.json

{
  "env": {
    "browser": true,
    "es6": true,
    "jest": true
  },
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 2018,
    "sourceType": "module"
  },
  "extends": ["airbnb-base"],
  "rules": {
    "no-shadow": "off",
    "no-param-reassign": "off",
    "eol-last": "off",
    "import/extensions": [ 1, {
      "js": "always", "json": "always"
    }]
  },
  "ignorePatterns": [
    "dist/",
    "build/"
  ]
}

如果我遗漏了什么,这是pull request with error

【问题讨论】:

  • 您应该在运行 eslint npm install 之前安装模块
  • 你是对的。 html-webpack-plugin 未安装在 GitHub 操作环境中。

标签: javascript webpack eslint bundler


【解决方案1】:

原来我的 html-webpack-plugin 没有安装在 GitHub 操作环境中,因为它不在 linters.yml 文件中。在linters.yml 中添加npm install html-webpack-plugin 解决了问题。

【讨论】:

    猜你喜欢
    • 2021-08-22
    • 2022-06-24
    • 2022-12-03
    • 2020-11-25
    • 2022-08-07
    • 1970-01-01
    • 2017-02-05
    • 2018-02-08
    • 2019-12-17
    相关资源
    最近更新 更多