webpack4.x 踩坑記錄

1. Error: Cannot find module ‘webpack/bin/config-yargs’

  1. 刪除 package.json 中的 webpack-dev-server
  2. 重新執行 npm i webpack-dev-server

2. TypeError: compilation.mainTemplate.applyPluginsWaterfall is not a function

終端執行 npm i --save-dev html-webpack-plugin@next

3. TypeError: Cannot read property ‘eslint’ of undefined

終端執行 npm install eslint-plugin-html

4. TypeError: Cannot read property ‘vue’ of undefined

終端執行: npm install vue-loader@latest --save-dev
webpack 配置

// webpack.config.js
const VueLoaderPlugin = require('vue-loader/lib/plugin')
module.exports = {
 module: { 
   rules: [
     // ... other rules
     {
       test: /\.vue$/,
       loader: 'vue-loader'
     }
   ]
 },
 plugins: [
   // make sure to include the plugin!
   new VueLoaderPlugin()
 ]
}

5. Invalid CSS after “…load the styles”: expected 1 selector or at-rule

原因: loader 重複
刪除/註釋以下配置

// webpack.config.js
// {
//   test: /\.scss$/,
//   use: [
//     'vue-style-loader',
//     'css-loader',
//     'sass-loader'
//   ]
// },
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章