项目场景:
将vite升级到vite4.0之后,使用hls播放m3u8的视频时,报错如下:
Uncaught TypeError: Cannot read properties of undefined (reading 'call')
at __webpack_require__3 (997125ee-68fb-4269-81dd-f71b50571fe8:155:48)
at ./src/demux/transmuxer-worker.ts (997125ee-68fb-4269-81dd-f71b50571fe8:11:66)
at __webpack_require__3 (997125ee-68fb-4269-81dd-f71b50571fe8:155:48)
at webpackBootstrapFunc2 (997125ee-68fb-4269-81dd-f71b50571fe8:207:28)
at 997125ee-68fb-4269-81dd-f71b50571fe8:209:15
解决方案:
方案1
解决方法将vite版本降低(3.2.5)
方案2
// import Hls from "hls.js"
import Hls from 'hls.js/dist/hls.min.js'
ts写法(vite.config.ts)
const alias: Record<string, string> = {
'~/': `${resolve(__dirname, 'src')}/`,
'hls.js': 'hls.js/dist/hls.min.js'
};