Laravel8使用webpack報錯的解決方法。ERROR in ./node_modules/vue-baberrage/dist/vue-baberrage.js 1:78-95.Module not found: Error: Can't resolve 'timers' in '/www/swooleItem/labarrage/node_modules/vue-baberrage/dist'
Vue-Baberrage
用它來做彈幕比較容易,那么安裝后啟動時報錯了錯誤,如下:
Compiled with some errors in 2.69s ERROR in ./node_modules/vue-baberrage/dist/vue-baberrage.js 1:78-95 Module not found: Error: Can't resolve 'timers' in '/www/swooleItem/labarrage/node_modules/vue-baberrage/dist' BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "timers": require.resolve("timers-browserify") }' - install 'timers-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "timers": false }
對于這個錯誤,大概的知道是webpack的原因,但為什么報錯,我就不知道了。我所有使用的版本是Laravel8。
一,安裝
npm install vue-baberrage
二,使用
位置:resources/js/app.js
import { vueBaberrage } from 'vue-baberrage' Vue.use(vueBaberrage)
三,啟動時編譯錯誤
npm run dev # 報錯,如上
解決方法
第一步:編輯webpack.mix.js
const mix = require('laravel-mix'); mix.js('resources/js/app.js', 'public/js') .vue() .sass('resources/sass/app.scss', 'public/css') // 新增如下配置 .webpackConfig(require('./webpack.config')); ~
第二步:創建wepack.config.js,并編輯如下內容
module.exports = { resolve: { fallback: { "timers": false }, fallback: { "timers": require.resolve("timers-browserify") } } };
第三步:npm install
第四步:npm run dev
至此,問題解決