vite 关于 global is not defined 问题

3,525 阅读1分钟

因为 Vite 是 ESM 机制,有些包内部使用了 node 的 global 对象,解决此问题可以通过自建 pollfill,然后在 main.ts 顶部引入,不是最优解

// polyfills
if (typeof (window as any).global === 'undefined') {
  ;(window as any).global = window
}

// main.ts
import './polyfills' // 注意要在createApp 的前面
import { createApp } from 'vue'

作者:追寻1989
链接:www.jianshu.com/p/b16404db4… 来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。