试着玩一下Electron,在macOS 12/13上打包exe文件时,踩了好几个坑,做个记录。

打包工具使用的是Electron快速入门教程里面推荐的 Electron Forge,在macOS上打包exe文件,需要依赖几个工具:wine、mono、xquartz,分别安装。然后执行打包命令,发现会卡在这个地方:

We need to package your application before we can make it
√ Preparing to Package Application for arch: x64
√ Compiling Application
√ Preparing native dependencies
√ Packaging Application
Making for the following targets:
× Making for target: squirrel - On platform: win32 - For arch: x64

此时,更改forge.config.js中的packgerConfig中的一个配置即可:

packagerConfig: {
  ...
  "asar":"true"
},

再次尝试,又出现如下错误:

Error {
    message: `Failed with exit code: 255

    Output:
    System.AggregateException: One or more errors occurred. () ---> System.Exception
      at Squirrel.Utility.CreateZipFromDirectory (System.String zipFilePath, System.String inFolder) [0x00119] in <a5ee691170b94c488950c75951ce1ba3>:0 
       --- End of inner exception stack trace ---
      at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00011] in <b6f643ae6ccb410db69142d5eaf9b9c1>:0 
      at System.Threading.Tasks.Task.Wait (System.Int32 millisecondsTimeout, System.Threading.CancellationToken cancellationToken) [0x00043] in <b6f643ae6ccb410db69142d5eaf9b9c1>:0 
      at System.Threading.Tasks.Task.Wait () [0x00000] in <b6f643ae6ccb410db69142d5eaf9b9c1>:0 
      at Squirrel.ReleasePackage.CreateReleasePackage (System.String outputFile, System.String packagesRootDir, System.Func`2[T,TResult] releaseNotesProcessor, System.Action`1[T] contentsPostProcessHook) [0x001f7] in <a5ee691170b94c488950c75951ce1ba3>:0 
      at Squirrel.Update.Program.Releasify (System.String package, System.String targetDir, System.String packagesDir, System.String bootstrapperExe, System.String backgroundGif, System.String signingOpts, System.String baseUrl, System.String setupIcon, System.Boolean generateMsi, System.String frameworkVersion, System.Boolean generateDeltas) [0x00214] in <a5ee691170b94c488950c75951ce1ba3>:0 
      at Squirrel.Update.Program.executeCommandLine (System.String[] args) [0x004a2] in <a5ee691170b94c488950c75951ce1ba3>:0 
      at Squirrel.Update.Program.main (System.String[] args) [0x00082] in <a5ee691170b94c488950c75951ce1ba3>:0 
      at Squirrel.Update.Program.Main (System.String[] args) [0x00006] in <a5ee691170b94c488950c75951ce1ba3>:0 
    ---> (Inner Exception #0) System.Exception
      at Squirrel.Utility.CreateZipFromDirectory (System.String zipFilePath, System.String inFolder) [0x00119] in <a5ee691170b94c488950c75951ce1ba3>:0 <---
    `,
  }

看起来是Squirrel里面出现了错误,找到一个issue,尝试了一下里面的方法,成功解决:

brew uninstall --cask xquartz
brew uninstall --cask wine-stable

brew tap gcenx/wine
brew install --cask --no-quarantine wine-crossover

macOS不再支持Squirrel.Windows,这个能跑起来应该也只是暂时的,以后打包可能还是需要个windows系统了。

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.