首先是vite5版本不支持require引入了,暂时的解决办法是在package.json中删掉 "type": "module",不报错但是有警告:The CJS build of Vite's Node API is deprecated.
再有就是打包时在github下载东西时超时报错,解决办法是在项目根目录新建 .npmrc 文件写入国内资源:
ELECTRON_MIRROR=https://npm.taobao.org/mirrors/electron/
ELECTRON_BUILDER_BINARIES_MIRROR=http://npm.taobao.org/mirrors/electron-builder-binaries/
如果配置完成了又报错:
⨯ cannot execute cause=exit status 2
out=
7-Zip (a) 21.07 (x64) : Copyright (c) 1999-2021 Igor Pavlov : 2021-12-26Scanning the drive for archives:
1 file, 5635384 bytes (5504 KiB).
.
.
.
这个报错是没有管理员权限,使用管理员身份运行PowerShell,cd进入项目目录执行打包命令即可
win11 右键点击win图标
打开终端管理员进入项目目录,执行打包命令就OK啦,之后就可以正常在vscode中进行打包了。