简体   繁体   English

如何解决 reactjs 中的“找不到模块 'webpack-cli/bin/config-yargs' 错误?

[英]How to solve 'Cannot find module 'webpack-cli/bin/config-yargs' error in reactjs?

When I run my first hello world react example, I got the following error.当我运行我的第一个 hello world react 示例时,出现以下错误。 How do I solve this?我该如何解决这个问题?

Error: Cannot find module 'webpack-cli/bin/config-yargs'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (.\ReactJS\node_modules\webpack-dev-server\bin\webpack-dev-server.
js:65:1)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)

package.json file: package.json 文件:

  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.5",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "webpack": "^4.16.5",
    "webpack-dev-server": "^3.1.5"
  },
  "dependencies": {
    "react": "^16.4.2",
    "react-dom": "^16.4.2",
    "start": "^5.1.0"
  }
}

2021 - the error is again actual. 2021 - 错误再次出现。 After upgrade to webpack 5 just replace the升级到 webpack 5 后只需替换

 webpack-dev-server --...

to same code command with到相同的代码命令

webpack serve --...

The error is telling you that you don't have webpack-cli installed.该错误告诉您没有安装webpack-cli You can install it and add it to your dev dependencies.您可以安装它并将其添加到您的开发依赖项中。

npm i -D webpack-cli

You also have a new version of Webpack installed with an outdated configuration object.您还安装了一个带有过时配置对象的新版本的 Webpack。 If you change configuration.module.loaders to configuration.module.rules it will work.如果您将configuration.module.loaders更改为configuration.module.rules它将起作用。

The reason was the versions of these libraries : — webpack , webpack-cli and webpack-dev-server.原因是这些库的版本:— webpack 、 webpack-cli 和 webpack-dev-server。 I fount out that the versions I used couldn't work together.我发现我使用的版本不能一起工作。 So I reinstall them and used the older versions which are:所以我重新安装它们并使用旧版本,它们是:

  1. "webpack": "^4.32.2", "webpack": "^4.32.2",
  2. "webpack-cli": "^3.3.2", "webpack-cli": "^3.3.2",
  3. "webpack-dev-server": "3.5.1" "webpack-dev-server": "3.5.1"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM