如何解决:Cannot find module vue loader lib plugin

一.问题描述

只是一个简单的用到了vuex的小项目,运行npm run dev之后,程序一直报错。报错信息如下:

vuex-learning@1.0.0 dev D:\workspace\LearningWeb\vue-basic\vuex-learning
> webpack-dev-server --mode development

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

Error: Cannot find module 'vue-loader/lib/plugin'
Require stack:
- D:\workspace\LearningWeb\vue-basic\vuex-learning\webpack.config.js
- D:\workspace\LearningWeb\vue-basic\vuex-learning\node_modules\webpack-cli\bin\utils\convert-argv.js
- D:\workspace\LearningWeb\vue-basic\vuex-learning\node_modules\webpack-dev-server\bin\webpack-dev-server.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
    at Function.Module._load (internal/modules/cjs/loader.js:840:27)
    at Module.require (internal/modules/cjs/loader.js:1019:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (D:\workspace\LearningWeb\vue-basic\vuex-learning\webpack.config.js:2:25)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Module.require (internal/modules/cjs/loader.js:1019:19) {
  code: 'MODULE_NOT_FOUND',

package.json文件信息如下:

{
  "name": "vuex-learning",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "webpack-dev-server --mode development"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@vue/component-compiler-utils": "^3.1.2",
    "css-loader": "^3.5.3",
    "html-webpack-plugin": "^4.3.0",
    "node-sass": "^4.14.1",
    "sass-loader": "^8.0.2",
    "style-loader": "^1.2.1",
    "vue": "^2.6.10",
    "vue-loader": "^15.7.0",
    "vue-template-compiler": "^2.6.10",
    "vuex": "^3.4.0",
    "webpack": "^4.43.0",
    "webpack-cli": "^3.3.11",
    "webpack-dev-server": "^3.11.0"
  }
}

二.解决方法

根据报错信息,不能找到’vue-loader/lib/plugin’这个模块。可是已经安装了vue-loader, 并且查看node_modules文件夹下,确实有这个文件。在排除了程序当中不存在其他错误之后,我做的唯一变化就是安装了vuex这个包。只能是vuex安装,引起了vuex与vue-loader版本不适配的问题引起的。我尝试着去查看了一下 vuex这里面用到的vue-loader版本号,是
“vue-loader”: “^15.2.1”, 所以我将原来的vue-loader卸载,重新安装,结果就不报错了。

  • npm uninstall vue-loader --save-dev
  • npm install vue-loader@^15.2.1

你可能感兴趣的:(JavaScript)