vite打包出现global is not defined和Buffer is not defined的解决方法

安装buffer

yarn add buffer

 

在main.ts里

 

import * as buffer from "buffer";

if (typeof (window as any).global === "undefined") {
(window as any).global = window;
}

if (typeof (window as any).Buffer === "undefined") {
(window as any).Buffer = buffer.Buffer;
}

 

posted @ 2022-08-03 01:26  冰糖雪梨橙  阅读(3345)  评论(0编辑  收藏  举报