eslint 設置 warning 級別,在 開發編譯失敗的原因,報錯如下: Module build failed: Module failed because of a eslint warning的原因,為自己當時即使是eslint 設置 warning 規則,在熱更新都會報錯,無法編譯通過的 ...
eslint 設置 warning 級別,在 開發編譯失敗的原因,報錯如下:
F:\vue-mobile-skeleton>npm run dev > [email protected] dev F:\vue-mobile-skeleton > webpack-dev-server --inline --progress --config build/webpack.dev.conf.js 94% asset optimization ERROR Failed to compile with 1 errors 22:51:17 error in ./src/app.vue Module build failed: Module failed because of a eslint warning. ⚠ http://eslint.org/docs/rules/no-unused-vars 'o' is assigned a value but never used src\app.vue:60:7 const o = 90; ^ ✘ 1 problem (0 errors, 1 warning) Warnings: 1 http://eslint.org/docs/rules/no-unused-vars @ ./src/main.js 12:0-28 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js
Module build failed: Module failed because of a eslint warning的原因,為自己當時即使是eslint 設置 warning 規則,在熱更新都會報錯,無法編譯通過的!
解決:
1:把這個沒有使用變數,刪除
2:使用 註釋方式不進行檢測 => // eslint-disable-next-line
3:把 eslint-laoder 的選項設置 fasle 即可;
// 目錄:/build/webpack.base.conf.js const createLintingRule = () => ({ test: /\.(js|vue)$/, loader: 'eslint-loader', enforce: 'pre', include: [resolve('src'), resolve('test')], options: { formatter: require('eslint-friendly-formatter'), emitError:false, emitWarning: config.dev.showEslintErrorsInOverlay, fix: true, failOnError: true, //如果有eslint警告,載入器將導致模塊構建失敗。 //設置 false 即可,去除此檢驗 failOnWarning: false, } })
但是,還是看個人喜好,若是單單在控制台提示警告也可以,不過我本人不想看到有警告,所以就硬性設為 true 不讓編譯通過,個人喜愛而已!