如何修复:错误:找不到模块'webpack-cli/bin/config-yargs'?

Posted

技术标签:

【中文标题】如何修复:错误:找不到模块\'webpack-cli/bin/config-yargs\'?【英文标题】:How to fix: Error: Cannot find module 'webpack-cli/bin/config-yargs'?如何修复:错误:找不到模块'webpack-cli/bin/config-yargs'? 【发布时间】:2021-02-13 02:47:45 【问题描述】:

我在互联网上查看了很多文章并尝试应用建议,但没有任何效果。

我的配置如下:

package.json:


  "name": "js_class",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "scripts": 
    "build": "webpack --config webpack.config.js",
    "webpack-dev-server": "webpack-dev-server",
    "dev": "webpack-dev-server --mode=development",
    "prod": "webpack --mode=production"
  ,
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": 
    "@babel/core": "^7.12.3",
    "@babel/preset-env": "^7.12.1",
    "babel-loader": "^8.1.0",
    "html-webpack-plugin": "^4.5.0",
    "path": "^0.12.7",
    "webpack": "^5.3.2",
    "webpack-cli": "^4.1.0",
    "webpack-dev-server": "^3.11.0"
  

webpack.config.js:

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

module.exports = 
  entry: './index.js',

  output: 
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  ,

  mode: 'development',
  module: 
    rules: [
      
        test: /\.js$/,
        exclude: /(node_modules)/,
        use: 
          loader: 'babel-loader',
          options: 
            presets: ['@babel/preset-env']
          
        
      
    ]
  ,
  devServer: 
    contentBase: path.join(__dirname, 'dist'),
    compress: true,
    port: 9000
  ,
  plugins: [
    new HtmlWebPackPlugin()
]
;

错误:

internal/modules/cjs/loader.js:834
  throw err;
  ^

Error: Cannot find module 'webpack-cli/bin/config-yargs'
Require stack:
- D:\Programiranje\Code\js\js_class\node_modules\webpack-dev-server\bin\webpack-dev-server.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:831:15)
    at Function.Module._load (internal/modules/cjs/loader.js:687:27)
    at Module.require (internal/modules/cjs/loader.js:903:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (D:\Programiranje\Code\js\js_class\node_modules\webpack-dev-server\bin\webpack-dev-server.js:65:1)
    at Module._compile (internal/modules/cjs/loader.js:1015:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
    at Module.load (internal/modules/cjs/loader.js:879:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12) 
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'D:\\Programiranje\\Code\\js\\js_class\\node_modules\\webpack-dev-server\\bin\\webpack-dev-server.js'
  ]

【问题讨论】:

我建议切换到webpack serve 命令而不是直接使用webpack-dev-server:github.com/webpack/webpack-dev-server/issues/…。 它没有帮助,但还是谢谢你。安装 webpack-cli 3.3.12 有帮助。 【参考方案1】:

安装 webpack-cli 3.3.12 帮助解决了这个问题。

【讨论】:

以上是关于如何修复:错误:找不到模块'webpack-cli/bin/config-yargs'?的主要内容,如果未能解决你的问题,请参考以下文章

npm 没有启动。错误:找不到模块“webpack-cli/bin/config-yargs”

错误:使用 webpack-cli 4.2.0 找不到模块“webpack-cli/bin/config-yargs”

错误:找不到模块“webpack/bin/config-yargs”

如何修复“错误:找不到模块'@endb/sqlite'”

如何修复material-kit-react'找不到模块:webpack loader错误'

如何修复 ElectronNET.CLI 找不到模块“fs/promises”。需要堆栈错误