Navigation

    GitHub中文社区
    • GitHub排行榜

    论坛

    • Login
    • Categories
    • Recent
    • Tags
    • Popular

    Electron 打包踩坑记录

    技术交流
    1
    1
    57
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • mango
      mango last edited by mango

      最近学习 Electron 开发桌面程序,打包exe过程中遇到几个坑记录下

      1.第一个坑,报symlink错误

      An unhandled rejection has occurred inside Forge:
      Error: EPERM: operation not permitted, symlink XXX -> C:\Users\xxx\AppData\Local\Temp\electron-packager\win32-x64...
      

      这是由于权限不足导致,解决方法使用使用管理员权限运行命令

      2.第二个坑,cnpm引发的内存泄漏

      An unhandled error has occurred inside Forge:
      An error occured while making for target: squirrel
      Failed with exit code: 1
      Output:
      ���ڳ��Դӡ�my_electron_app.nuspec�����ɳ������
      ָ����·�����ļ���̫�����������߶�̫������ȫ�޶��ļ����������� 260 ���ַ�������Ŀ¼���������� 248 ���ַ���
      
          at ChildProcess.<anonymous> (D:\my-electron-app\node_modules\_electron-winstaller@5.0.0@electron-winstaller\lib\spawn-promise.js:49:24)
          at ChildProcess.emit (events.js:400:28)
          at ChildProcess.emit (domain.js:470:12)
          at maybeClose (internal/child_process.js:1055:16)
          at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
      

      这个最坑,困扰了很久。看别人说是使用cnpm安装依赖导致的内存泄漏,于是把node_modules目录删了,重新用npm install 果然没问题了。

      npm与cnpm的区别

      说到npm与cnpm的区别,可能大家都知道,但大家容易忽视的一点,是cnpm装的各种node_module,这种方式下所有的包都是扁平化的安装。一下子node_modules展开后有非常多的文件。导致了在打包的过程中非常慢。但是如果改用npm来安装node_modules的话,所有包都是树状结构的,层级变深。
      由于这个不同,对一些项目比较大的应用,很容易出现打包过程慢且node内存溢出的问题(这 也是在解决electron打包过程中困扰我比较久的问题,最后想到了npm与cnpm的这点不>同,解决了node打包内存溢出的问题,从打包一次一小时优化到打包一次一分钟,极大的提高了效率)。
      所以建议大家在打包前,讲使用cnpm安装的依赖包删除,替换成npm安装的依赖包。

      1 Reply Last reply Reply Quote 0
      • First post
        Last post