npm run build 报错 请问是哪里的问题

来源:2-3 webpack-dev-server的配置和使用

慕标4068903

2019-07-12 16:45

> vue-ssr-tech@1.0.0 build E:\workspace\整理文件web\综合练习\vue\vue核心技术\VUE-SSR-TECH
> webpack --config webpack.config.js

Hash: 96a4b1c95b2729429677
Version: webpack 4.35.3
Time: 480ms
Built at: 2019-07-12 16:36:36
 1 asset
Entrypoint main = bundle.js
[0] (webpack)/buildin/global.js 472 bytes {0} [built]
[2] ./src/index.js 186 bytes {0} [built]
[3] ./src/app.vue 426 bytes {0} [built] [failed] [3 errors]
    + 4 hidden modules

WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/

ERROR in ./src/app.vue
Module Error (from ./node_modules/vue-loader/lib/index.js):
[vue-loader] vue-template-compiler must be installed as a peer dependency, or a compatible compiler implementation must be passed via options.
 @ ./src/index.js 2:0-27

ERROR in ./src/app.vue
Module Error (from ./node_modules/vue-loader/lib/index.js):
vue-loader was used without the corresponding plugin. Make sure to include VueLoaderPlugin in your webpack config.
 @ ./src/index.js 2:0-27

ERROR in ./src/app.vue
Module build failed (from ./node_modules/vue-loader/lib/index.js):
TypeError: Cannot read property 'parseComponent' of undefined
    at parse (E:\workspace\整理文件web\综合练习\vue\vue核心技术\VUE-SSR-TECH\node_modules\@vue\component-compiler-utils\dist\parse.js:14:23)
    at Object.module.exports (E:\workspace\整理文件web\综合练习\vue\vue核心技术\VUE-SSR-TECH\node_modules\vue-loader\lib\index.js:67:22)
 @ ./src/index.js 2:0-27
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! vue-ssr-tech@1.0.0 build: `webpack --config webpack.config.js`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the vue-ssr-tech@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2019-07-12T08_36_36_666Z-debug.log
PS E:\workspace\整理文件web\综合练习\vue\vue核心技术\VUE-SSR-TECH> npm run build

> vue-ssr-tech@1.0.0 build E:\workspace\整理文件web\综合练习\vue\vue核心技术\VUE-SSR-TECH
> webpack --config webpack.config.js

Hash: 96a4b1c95b2729429677
Version: webpack 4.35.3
Time: 508ms
Built at: 2019-07-12 16:38:41
 1 asset
Entrypoint main = bundle.js
[0] (webpack)/buildin/global.js 472 bytes {0} [built]
[2] ./src/index.js 186 bytes {0} [built]
[3] ./src/app.vue 426 bytes {0} [built] [failed] [3 errors]
    + 4 hidden modules

WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/

ERROR in ./src/app.vue
Module Error (from ./node_modules/vue-loader/lib/index.js):
[vue-loader] vue-template-compiler must be installed as a peer dependency, or a compatible compiler implementation must be passed via options.
 @ ./src/index.js 2:0-27

ERROR in ./src/app.vue
Module Error (from ./node_modules/vue-loader/lib/index.js):
vue-loader was used without the corresponding plugin. Make sure to include VueLoaderPlugin in your webpack config.
 @ ./src/index.js 2:0-27

ERROR in ./src/app.vue
Module build failed (from ./node_modules/vue-loader/lib/index.js):
TypeError: Cannot read property 'parseComponent' of undefined
    at parse (E:\workspace\整理文件web\综合练习\vue\vue核心技术\VUE-SSR-TECH\node_modules\@vue\component-compiler-utils\dist\parse.js:14:23)
    at Object.module.exports (E:\workspace\整理文件web\综合练习\vue\vue核心技术\VUE-SSR-TECH\node_modules\vue-loader\lib\index.js:67:22)
 @ ./src/index.js 2:0-27
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! vue-ssr-tech@1.0.0 build: `webpack --config webpack.config.js`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the vue-ssr-tech@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2019-07-12T08_38_41_819Z-debug.log

----------------------------------------------------------------------------------------------------------------------------

webpack.json.js文件:

const path = require('path')

module.exports = {

   entry:path.join(__dirname,'src/index.js'),

   output:{

       filename:'bundle.js',

       path:path.join(__dirname,'dist')

   },

   module:{

       rules:[

           {

               test: /.vue$/,

               loader: 'vue-loader'

           }

       ]

   }

}

-------------------------------------------------------------------------------------------------

package.json文件:

{

 "name": "vue-ssr-tech",

 "version": "1.0.0",

 "main": "index.js",

 "scripts": {

   "dev": "webpack --mode development",

   "test": "echo \"Error: no test specified\" && exit 1",

   "build": "webpack --config webpack.config.js"

 },

 "author": "",

 "license": "ISC",

 "dependencies": {

   "css-loader": "^3.0.0",

   "vue": "^2.6.10",

   "vue-loader": "^15.7.0",

   "webpack": "^4.35.3"

 },

 "devDependencies": {

   "webpack-cli": "^3.3.5"

 },

 "description": ""

}


写回答 关注

2回答

  • 慕沐8789467
    2019-07-26 15:21:50

    错误提示你的包依赖没有装好

    你可以参考一下我的代码https://github.com/carrieguo/vue.js-learn


  • 慕妹4518891
    2019-07-12 21:35:28

    ERROR in ./src/app.vue
    Module Error (from ./node_modules/vue-loader/lib/index.js):
    [vue-loader] vue-template-compiler must be installed as a peer dependency, or a compatible compiler implementation must be passed via options.

    没有安装 vue-template-compiler 模块, 在vs-code里打开终端,确保是在当前项目,执行 npm run vue-template-compiler.(一定要在当前项目打开终端, 之前老用cmd打开安装,老是找不到模块)

Vue+Webpack打造todo应用

用前端最热门框架Vue+最火打包工具Webpack打造todo应用

84606 学习 · 787 问题

查看课程

相似问题