alex8088 / electron-vite

Next generation Electron build tooling based on Vite 新一代 Electron 开发构建工具,支持源代码保护
https://electron-vite.org
MIT License
3.47k stars 150 forks source link

MacOS 系统中,无法通过 pnpm 在 Electron 25.9.0 版本正常启动 #304

Closed Cat7373 closed 1 year ago

Cat7373 commented 1 year ago

Describe the bug

系统环境:

  1. Macbook Pro 13 寸(M1 芯片)
  2. MacOS 14.0
  3. fish 3.6.1
  4. NodeJS 20.7.0
  5. Npm 10.1.0

测试步骤:

  1. 参照官方快速开始指引,运行pnpm create @quick-start/electron my-app --template vue
  2. 进入 my-app 目录
  3. 运行 pnpm i
  4. 运行 pnpm run dev
  5. 应用程序异常退出

操作记录:

cat73@Cats-MacBook-Pro ~/Documents> pnpm create @quick-start/electron my-app --template vue
../Library/pnpm/store/v3/tmp/dlx-6250    |   +8 +
../Library/pnpm/store/v3/tmp/dlx-6250    | Progress: resolved 8, reused 8, downloaded 0, added 8, done
✔ Add TypeScript? … No / Yes
✔ Add Electron updater plugin? … No / Yes
✔ Enable Electron download mirror proxy? … No / Yes

Scaffolding project in /Users/cat73/Documents/my-app...

Done. Now run:

  cd my-app
  pnpm install
  pnpm dev

cat73@Cats-MacBook-Pro ~/Documents> cd my-app/
cat73@Cats-MacBook-Pro ~/D/my-app> pnpm i
Packages: +439
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Progress: resolved 460, reused 439, downloaded 0, added 439, done

> my-app@1.0.0 postinstall /Users/cat73/Documents/my-app
> electron-builder install-app-deps

  • electron-builder  version=24.6.4
  • loaded configuration  file=/Users/cat73/Documents/my-app/electron-builder.yml

dependencies:
+ @electron-toolkit/preload 2.0.0
+ @electron-toolkit/utils 2.0.1
+ electron-updater 6.1.4

devDependencies:
+ @electron-toolkit/eslint-config 1.0.1
+ @rushstack/eslint-patch 1.5.1
+ @vitejs/plugin-vue 4.4.0
+ @vue/eslint-config-prettier 8.0.0
+ electron 25.9.0 (26.3.0 is available)
+ electron-builder 24.6.4
+ electron-vite 1.0.28
+ eslint 8.51.0
+ eslint-plugin-vue 9.17.0
+ less 4.2.0
+ prettier 3.0.3
+ vite 4.4.11
+ vue 3.3.4

Done in 10.7s
cat73@Cats-MacBook-Pro ~/D/my-app> pnpm run dev

> my-app@1.0.0 dev /Users/cat73/Documents/my-app
> electron-vite dev

vite v4.4.11 building for development...
✓ 2 modules transformed.
out/main/index.js  1.43 kB
✓ built in 50ms

build the electron main process successfully

-----

vite v4.4.11 building for development...
✓ 1 modules transformed.
out/preload/index.js  0.42 kB
✓ built in 6ms

build the electron preload files successfully

-----

dev server running for the electron renderer process at:

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose

start electron app...

dyld[6591]: Library not loaded: @rpath/Electron Framework.framework/Electron Framework
  Referenced from: <4C4C4484-5555-3144-A148-DF651B150242> /Users/cat73/Documents/my-app/node_modules/.pnpm/electron@25.9.0/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron
  Reason: tried: '/Users/cat73/Documents/my-app/node_modules/.pnpm/electron@25.9.0/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Electron Framework' (no such file), '/Users/cat73/Documents/my-app/node_modules/.pnpm/electron@25.9.0/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Electron Framework' (no such file), '/Library/Frameworks/Electron Framework.framework/Electron Framework' (no such file), '/System/Library/Frameworks/Electron Framework.framework/Electron Framework' (no such file, not in dyld cache)
cat73@Cats-MacBook-Pro ~/D/my-app> 

报错截图:

image

完整报错内容:

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Process:               Electron [6824]
Path:                  /Users/USER/Documents/*/Electron.app/Contents/MacOS/Electron
Identifier:            com.github.Electron
Version:               25.9.0 (25.9.0)
Code Type:             ARM-64 (Native)
Parent Process:        node [6817]
Responsible:           Electron [11187]
User ID:               501

Date/Time:             2023-10-09 16:01:22.2833 +0800
OS Version:            macOS 14.0 (23A339)
Report Version:        12
Anonymous UUID:        29BFEB39-22EA-1B41-913A-659DC1F193C4

Sleep/Wake UUID:       8F2C0FDA-8BB4-4122-BE2C-BC479651147C

Time Awake Since Boot: 750000 seconds
Time Since Wake:       16187 seconds

System Integrity Protection: enabled

Crashed Thread:        0

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000

Termination Reason:    Namespace DYLD, Code 1 Library missing
Library not loaded: @rpath/Electron Framework.framework/Electron Framework
Referenced from: <4C4C4484-5555-3144-A148-DF651B150242> /Users/USER/Documents/*/Electron.app/Contents/MacOS/Electron
Reason: tried: '/Users/cat73/Documents/my-app/node_modules/.pnpm/electron@25.9.0/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Electron Framework' (no such file), '/Users/cat73/Documents/my-app/node_modules/.pnpm/electron@25.9.0/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Electron Framework' (no such file), '/Library/Frameworks/Electron Framework.framework/Electron Framework' (no such file), '/System/Library/Frameworks/Electron Framework.framework/Electron Framework' (no such file, not in dyld cache)
(terminated at launch; ignore backtrace)

Thread 0 Crashed:
0   dyld                                   0x18d239b48 __abort_with_payload + 8
1   dyld                                   0x18d246108 abort_with_payload_wrapper_internal + 104
2   dyld                                   0x18d24613c abort_with_payload + 16
3   dyld                                   0x18d1cd518 dyld4::halt(char const*, dyld4::StructuredError const*) + 304
4   dyld                                   0x18d1ca1e8 dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 3884
5   dyld                                   0x18d1c8f44 start + 1948

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000006   x1: 0x0000000000000001   x2: 0x000000016f6f5090   x3: 0x00000000000000cc
    x4: 0x000000016f6f4c90   x5: 0x0000000000000000   x6: 0x0000000000000000   x7: 0x00000000000005b0
    x8: 0x0000000000000020   x9: 0x000000016f6f4c12  x10: 0x000000000000000a  x11: 0x0000000000000000
   x12: 0x0000000000000036  x13: 0x1000000000000000  x14: 0x0000000000000004  x15: 0x0000000000008000
   x16: 0x0000000000000209  x17: 0x000000018d1c637c  x18: 0x0000000000000000  x19: 0x0000000000000000
   x20: 0x000000016f6f4c90  x21: 0x00000000000000cc  x22: 0x000000016f6f5090  x23: 0x0000000000000001
   x24: 0x0000000000000006  x25: 0x000000016f6f5ac8  x26: 0x000000016f6f5a08  x27: 0x0000000000000000
   x28: 0x000000001f070004   fp: 0x000000016f6f4c60   lr: 0x000000018d246108
    sp: 0x000000016f6f4c20   pc: 0x000000018d239b48 cpsr: 0x80001000
   far: 0x0000000100b68000  esr: 0x56000080  Address size fault

Binary Images:
       0x100708000 -        0x10070bfff com.github.Electron (25.9.0) <4c4c4484-5555-3144-a148-df651b150242> /Users/USER/Documents/*/Electron.app/Contents/MacOS/Electron
       0x18d1c3000 -        0x18d256873 dyld (*) <ee3f4181-cec5-38c2-b8a8-4d310be33491> /usr/lib/dyld
               0x0 - 0xffffffffffffffff ??? (*) <00000000-0000-0000-0000-000000000000> ???

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0

VM Region Summary:
ReadOnly portion of Libraries: Total=887.0M resident=0K(0%) swapped_out_or_unallocated=887.0M(100%)
Writable regions: Total=12.2M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=12.2M(100%)

                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
STACK GUARD                       56.0M        1 
Stack                             8176K        1 
VM_ALLOCATE                         16K        1 
__DATA                              27K        2 
__DATA_CONST                        38K        2 
__DATA_DIRTY                         7K        1 
__LINKEDIT                       886.5M        2 
__TEXT                             608K        2 
dyld private memory               4384K        4 
===========                     =======  ======= 
TOTAL                            955.4M       16 

-----------
Full Report
-----------

{"app_name":"Electron","timestamp":"2023-10-09 16:01:22.00 +0800","app_version":"25.9.0","slice_uuid":"4c4c4484-5555-3144-a148-df651b150242","build_version":"25.9.0","platform":1,"bundleID":"com.github.Electron","share_with_app_devs":1,"is_first_party":0,"bug_type":"309","os_version":"macOS 14.0 (23A339)","roots_installed":0,"name":"Electron","incident_id":"41A07F64-A221-43E4-846B-B64AC42FE4D3"}
{
  "uptime" : 750000,
  "procRole" : "Unspecified",
  "version" : 2,
  "userID" : 501,
  "deployVersion" : 210,
  "modelCode" : "MacBookPro17,1",
  "coalitionID" : 109493,
  "osVersion" : {
    "train" : "macOS 14.0",
    "build" : "23A339",
    "releaseType" : "User"
  },
  "captureTime" : "2023-10-09 16:01:22.2833 +0800",
  "codeSigningMonitor" : 1,
  "incident" : "41A07F64-A221-43E4-846B-B64AC42FE4D3",
  "pid" : 6824,
  "translated" : false,
  "cpuType" : "ARM-64",
  "roots_installed" : 0,
  "bug_type" : "309",
  "procLaunch" : "2023-10-09 16:01:22.2821 +0800",
  "procStartAbsTime" : 18181583050537,
  "procExitAbsTime" : 18181583074637,
  "procName" : "Electron",
  "procPath" : "\/Users\/USER\/Documents\/*\/Electron.app\/Contents\/MacOS\/Electron",
  "bundleInfo" : {"CFBundleShortVersionString":"25.9.0","CFBundleVersion":"25.9.0","CFBundleIdentifier":"com.github.Electron"},
  "storeInfo" : {"deviceIdentifierForVendor":"7A9FFD05-B51D-5AB2-8174-54766554F2BE","thirdParty":true},
  "parentProc" : "node",
  "parentPid" : 6817,
  "coalitionName" : "com.microsoft.VSCode",
  "crashReporterKey" : "29BFEB39-22EA-1B41-913A-659DC1F193C4",
  "responsiblePid" : 11187,
  "responsibleProc" : "Electron",
  "codeSigningID" : "Electron",
  "codeSigningTeamID" : "",
  "codeSigningFlags" : 570556929,
  "codeSigningValidationCategory" : 10,
  "codeSigningTrustLevel" : 4294967295,
  "instructionByteStream" : {"beforePC":"NAEAANQAAAAQAQAAGAEAACABAAAoAQAAMAEAAEwBAAAwQYDSARAA1A==","atPC":"AwEAVH8jA9X9e7+p\/QMAkcww\/pe\/AwCR\/XvBqP8PX9bAA1\/WEC2A0g=="},
  "wakeTime" : 16187,
  "sleepWakeUUID" : "8F2C0FDA-8BB4-4122-BE2C-BC479651147C",
  "sip" : "enabled",
  "exception" : {"codes":"0x0000000000000000, 0x0000000000000000","rawCodes":[0,0],"type":"EXC_CRASH","signal":"SIGABRT"},
  "termination" : {"code":1,"flags":518,"namespace":"DYLD","indicator":"Library missing","details":["(terminated at launch; ignore backtrace)"],"reasons":["Library not loaded: @rpath\/Electron Framework.framework\/Electron Framework","Referenced from: <4C4C4484-5555-3144-A148-DF651B150242> \/Users\/USER\/Documents\/*\/Electron.app\/Contents\/MacOS\/Electron","Reason: tried: '\/Users\/cat73\/Documents\/my-app\/node_modules\/.pnpm\/electron@25.9.0\/node_modules\/electron\/dist\/Electron.app\/Contents\/Frameworks\/Electron Framework.framework\/Electron Framework' (no such file), '\/Users\/cat73\/Documents\/my-app\/node_modules\/.pnpm\/electron@25.9.0\/node_modules\/electron\/dist\/Electron.app\/Contents\/Frameworks\/Electron Framework.framework\/Electron Framework' (no such file), '\/Library\/Frameworks\/Electron Framework.framework\/Electron Framework' (no such file), '\/System\/Library\/Frameworks\/Electron Framework.framework\/Electron Framework' (no such file, not in dyld cache)"]},
  "extMods" : {"caller":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"system":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"targeted":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"warnings":0},
  "faultingThread" : 0,
  "threads" : [{"triggered":true,"id":14141066,"threadState":{"x":[{"value":6},{"value":1},{"value":6164533392},{"value":204},{"value":6164532368},{"value":0},{"value":0},{"value":1456},{"value":32},{"value":6164532242},{"value":10},{"value":0},{"value":54},{"value":1152921504606846976},{"value":4},{"value":32768},{"value":521},{"value":6662415228,"symbolLocation":416,"symbol":"__simple_bprintf"},{"value":0},{"value":0},{"value":6164532368},{"value":204},{"value":6164533392},{"value":1},{"value":6},{"value":6164536008},{"value":6164535816},{"value":0},{"value":520552452}],"flavor":"ARM_THREAD_STATE64","lr":{"value":6662938888},"cpsr":{"value":2147487744},"fp":{"value":6164532320},"sp":{"value":6164532256},"esr":{"value":1442840704,"description":" Address size fault"},"pc":{"value":6662888264,"matchesCrashFrame":1},"far":{"value":4306927616}},"frames":[{"imageOffset":486216,"symbol":"__abort_with_payload","symbolLocation":8,"imageIndex":1},{"imageOffset":536840,"symbol":"abort_with_payload_wrapper_internal","symbolLocation":104,"imageIndex":1},{"imageOffset":536892,"symbol":"abort_with_payload","symbolLocation":16,"imageIndex":1},{"imageOffset":42264,"symbol":"dyld4::halt(char const*, dyld4::StructuredError const*)","symbolLocation":304,"imageIndex":1},{"imageOffset":29160,"symbol":"dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*)","symbolLocation":3884,"imageIndex":1},{"imageOffset":24388,"symbol":"start","symbolLocation":1948,"imageIndex":1}]}],
  "usedImages" : [
  {
    "source" : "P",
    "arch" : "arm64",
    "base" : 4302340096,
    "CFBundleShortVersionString" : "25.9.0",
    "CFBundleIdentifier" : "com.github.Electron",
    "size" : 16384,
    "uuid" : "4c4c4484-5555-3144-a148-df651b150242",
    "path" : "\/Users\/USER\/Documents\/*\/Electron.app\/Contents\/MacOS\/Electron",
    "name" : "Electron",
    "CFBundleVersion" : "25.9.0"
  },
  {
    "source" : "P",
    "arch" : "arm64e",
    "base" : 6662402048,
    "size" : 604276,
    "uuid" : "ee3f4181-cec5-38c2-b8a8-4d310be33491",
    "path" : "\/usr\/lib\/dyld",
    "name" : "dyld"
  },
  {
    "size" : 0,
    "source" : "A",
    "base" : 0,
    "uuid" : "00000000-0000-0000-0000-000000000000"
  }
],
  "sharedCache" : {
  "base" : 6661652480,
  "size" : 4012507136,
  "uuid" : "82432966-0197-3a07-bff2-d3c8205c5ed8"
},
  "vmSummary" : "ReadOnly portion of Libraries: Total=887.0M resident=0K(0%) swapped_out_or_unallocated=887.0M(100%)\nWritable regions: Total=12.2M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=12.2M(100%)\n\n                                VIRTUAL   REGION \nREGION TYPE                        SIZE    COUNT (non-coalesced) \n===========                     =======  ======= \nSTACK GUARD                       56.0M        1 \nStack                             8176K        1 \nVM_ALLOCATE                         16K        1 \n__DATA                              27K        2 \n__DATA_CONST                        38K        2 \n__DATA_DIRTY                         7K        1 \n__LINKEDIT                       886.5M        2 \n__TEXT                             608K        2 \ndyld private memory               4384K        4 \n===========                     =======  ======= \nTOTAL                            955.4M       16 \n",
  "legacyInfo" : {
  "threadTriggered" : {

  }
},
  "logWritingSignature" : "4fe030f81cf021339662d029e38eb44395eca60b",
  "trialInfo" : {
  "rollouts" : [
    {
      "rolloutId" : "6112d17137f5d11121dcd4e2",
      "factorPackIds" : {

      },
      "deploymentId" : 240000413
    },
    {
      "rolloutId" : "5f72dc58705eff005a46b3a9",
      "factorPackIds" : {

      },
      "deploymentId" : 240000015
    }
  ],
  "experiments" : [
    {
      "treatmentId" : "1440dc29-c885-4b83-9dd3-e99d18591e4d",
      "experimentId" : "6424c6bdb5f78353c42c33cf",
      "deploymentId" : 400000011
    },
    {
      "treatmentId" : "a092db1b-c401-44fa-9c54-518b7d69ca61",
      "experimentId" : "64a844035c85000c0f42398a",
      "deploymentId" : 400000019
    }
  ]
}
}

Electron-Vite Version

1.0.27

Electron Version

25.6.0

Vite Version

4.4.9

Validations

Cat7373 commented 1 year ago

简单研究后发现,它找不到的文件,实际在路径上添加一个 /Versions/A/ 就能找到了,参照下面:

cat73@cat73-mbp ~/D/my-app> ll -l '/Users/cat73/Documents/my-app/node_modules/.pnpm/electron@25.9.0/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Electron Framework'
ls: /Users/cat73/Documents/my-app/node_modules/.pnpm/electron@25.9.0/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Electron Framework: No such file or directory
cat73@cat73-mbp ~/D/my-app> ll -l '/Users/cat73/Documents/my-app/node_modules/.pnpm/electron@25.9.0/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework' 
-rwxr-xr-x  4 cat73  staff   131M Oct  9 15:45 /Users/cat73/Documents/my-app/node_modules/.pnpm/electron@25.9.0/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework*
cat73@cat73-mbp ~/D/my-app> 

两个路径关键部分对比如下:

  1. Electron.app/Contents/Frameworks/Electron Framework.framework/Electron Framework
  2. Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework
alex8088 commented 1 year ago

pnpm 什么版本? 可以使用npm确认是否有问题。

Cat7373 commented 1 year ago

pnpm 是 8.7.4,我在尝试降级 Electron 到 20.x,如果不行,下一个尝试用 npm

Cat7373 commented 1 year ago

更新package.json中依赖为"electron": "=20.3.12",后,正常启动运行,仍然使用 pnpm,我开始逐步尝试升级,找到问题版本

Cat7373 commented 1 year ago

测试记录:

  1. 21.4.4 正常
  2. 22.3.26 正常
  3. 23.3.13 正常
  4. 24.8.6 正常
  5. 25.9.0 启动崩溃
  6. 25.0.0 正常
  7. 25.5.0 正常
  8. 25.7.0 正常
  9. 25.8.4 正常

定位问题出在 electron 25.9.0 这个版本中,更新日志倒是没什么特别的内容:

https://github.com/electron/electron/releases/tag/v25.9.0

代码变更中也没搜到 Versions,对我来说,问题暂时算解决了,可以正常用了,后续排查,我可能帮不上太大忙了,需要帮忙测什么的话,回复就可以,别太复杂都可以哈

https://github.com/electron/electron/compare/v25.9.0...25-x-y

alex8088 commented 1 year ago

@Cat7373 针对25.9.0我在windows和mac测试都没有问题,猜测是pnpm导致,你可以尝试删除pnpm的electron25.9.0版本的缓存并重新下载或者通过其他包管理器测试,也没有看到electron有相关issue。

Cat7373 commented 1 year ago

更新:经测试,确实 npm 可用,pnpm 报错