vue-cli 新创建的项目启动报错 Module build failed: Error: "extract-text-webpack-plugin"
2017-12-01 00:00
951 查看
问题
使用vue-cli新创建工程,并且已经
npm install成功安装所有依赖包,运行
$ npm start时报以下错误。
error in ./src/App.vue Module build failed: Error: "extract-text-webpack-plugin" loader is used without the corresponding plugin, refer to https://github.com/webpack/extract-text-webpack-plugin for the usage example at Object.pitch (D:\study\vue\my-project\node_modules\extract-text-webpack-plugin\dist\loader.js:57:11) @ ./src/App.vue 2:2-358 @ ./src/main.js @ multi (webpack)-dev-server/client?http://localhost:8081 webpack/hot/dev-server ./src/main.js error in ./src/components/HelloWorld.vue Module build failed: Error: "extract-text-webpack-plugin" loader is used without the corresponding plugin, refer to https://github.com/webpack/extract-text-webpack-plugin for the usage example at Object.pitch (D:\study\vue\my-project\node_modules\extract-text-webpack-plugin\dist\loader.js:57:11) @ ./src/components/HelloWorld.vue 2:2-373 @ ./src/router/index.js @ ./src/main.js @ multi (webpack)-dev-server/client?http://localhost:8081 webpack/hot/dev-server ./src/main.js
分析
extract-text-webpack-plugin
在报错信息中,看到
failed: Error: "extract-text-webpack-plugin",它是 webpack 的一个插件:用于在打包项目代码时将 css 代码从 js 代码中分离出去,于是就猜测是不是这个插件配置有问题。在
vue-cli工具生成的目录结构中找到
build目录,其中存放 webpack 的配置文件,包含了 base(基础配置,公共部分)、dev(开发配置)、prod(生产配置)等配置文件,那么到底是哪个配置文件影响了呢?
$ npm start
"scripts": { "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js", "start": "npm run dev", "test": "npm run unit", "lint": "eslint --ext .js,.vue src test/unit/specs", "build": "node build/build.js" },
在 package.json 中可以看到运行
$ npm start实际上运行的是
webpack-dev-server --inline --progress --config build/webpack.dev.conf.js,这句话的含义是使用 webpack 本地服务器启动项目,并且根据
webpack.dev.conf.js配置文件对项目进行打包编译。
webpack.dev.conf.js
打开
webpack.dev.conf.js文件,可以看到里面压根就没有配置过
extract-text-webpack-plugin这个插件,猜测可能是这个问题导致的。
解决
在webpack.dev.conf.js中添加
extract-text-webpack-plugin配置如下。重启
$ npm start可以看到此时项目被成功启动,并且在浏览器中可以看到 Vue 的欢迎界面。
const ExtractTextPlugin = require('extract-text-webpack-plugin') ........ plugins: [ ............. // extract css into its own file new ExtractTextPlugin({ filename: utils.assetsPath('css/[name].[contenthash].css'), // set the following option to `true` if you want to extract CSS from // codesplit chunks into this main css file as well. // This will result in *all* of your app's CSS being loaded upfront. allChunks: false, }), ]
相关文章推荐
- webpack---Error in app.js ;Module build failed :SyntaxError ../app.js : unpexted token <7:8> 对'<'报错
- vue-cli创建的项目不需要再创建webpack-config.js文件,因为已经配置过了
- Vue+Webpack配置css-loader时报错:Module build failed: Unknown word
- webpack "extract-text-webpack-plugin" 打包报错loader is used without the corresponding plugin
- 【node-sass】 Module build failed: Error: ENOENT: no such file or directory, scandir 'C:\Users\lizhaohong\Desktop\testwebpack\node_modules\.4.7.2@node-sass\vendor'
- 用npm安装vue和vue-cli,并使用webpack创建项目的方法
- extract-text-webpack-plugin" loader is used without the corresponding plugin How to deal
- vue-cli+webpack记事本项目创建
- 用npm安装vue和vue-cli,并使用webpack创建项目
- vue-cli webpack项目npm run dev启动过程
- webpack ERROR in ( your module path) Module build failed: Unknown word
- 关于webpack项目中报错:Error: Cannot find module 'webpack/lib/node/NodeTemplatePlugin' 的解决办法
- vue-cli的webpack模版项目配置解析-build/dev-server.js
- Failed to sync Gradle project '项目名称(module)' Error:failed to find Build Tools revision 20.1.2
- vue-cli项目在IE下运行钩子函数抛出异常“ReferenceError: “Promise”未定义"”的解决办法
- 【23】使用vue-cli脚手架搭建webpack项目基本结构
- 让Vue-cli生成vue+webpack的项目为vue1.0版本以及端口占用问题解决办法
- vue-cli的webpack模板项目配置文件分析
- Vue-webpack环境的搭建及项目的创建
- vue-cli webpack2项目打包优化