alex8088 / electron-vite

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

使用 Electron Forge 打包失败 #360

Closed toFrankie closed 10 months ago

toFrankie commented 10 months ago

Describe the bug

使用 Electron Forge 分发应用程序指引调整后,执行打包出错:

$ pnpm package
> menu-bar-tool@0.0.1 package /Users/frankie/Web/Git/menu-bar-tool
> pnpm run tsc && electron-vite build --outDir=dist && electron-forge package

> menu-bar-tool@0.0.1 tsc /Users/frankie/Web/Git/menu-bar-tool
> pnpm run tsc:node && pnpm run tsc:web

> menu-bar-tool@0.0.1 tsc:node /Users/frankie/Web/Git/menu-bar-tool
> tsc --noEmit -p tsconfig.node.json --composite false

> menu-bar-tool@0.0.1 tsc:web /Users/frankie/Web/Git/menu-bar-tool
> tsc --noEmit -p tsconfig.web.json --composite false

vite v5.0.10 building SSR bundle for production...
✓ 2 modules transformed.
dist/main/index.js  1.43 kB
✓ built in 57ms
vite v5.0.10 building SSR bundle for production...
✓ 1 modules transformed.
dist/preload/index.js  0.42 kB
✓ built in 8ms
vite v5.0.10 building for production...
✓ 32 modules transformed.
../../dist/renderer/index.html                   0.52 kB
../../dist/renderer/assets/icons-p39i8CQ2.svg    9.06 kB
../../dist/renderer/assets/index-ME2HaU7H.css    2.88 kB
../../dist/renderer/assets/index-ZHdq04n_.js   228.87 kB
✓ built in 570ms
✔ Checking your system
✔ Preparing to package application
✔ Running packaging hooks
  ✔ Running generateAssets hook
  ✔ Running prePackage hook
❯ Packaging application
  › Determining targets...
  ❯ Packaging for x64 on darwin
    ✔ Copying files
    ⠦ Preparing native dependencies
    ◼ Finalizing package
◼ Running postPackage hook

An unhandled rejection has occurred inside Forge:
Error: ENOENT: no such file or directory, stat '/private/var/folders/rq/kl256j8n5_vdkffj82kyjkfc0000gn/T/electron-packager/tmp-0xDzVX/Electron.app/Contents/Resources/app/node_modules/@electron-toolkit/preload'

 ELIFECYCLE  Command failed with exit code 1.

看起来这个链接文件找不到出处了

$ ll /var/folders/rq/kl256j8n5_vdkffj82kyjkfc0000gn/T/electron-packager/tmp-0xDzVX/Electron.app/Contents/Resources/app/node_modules/@electron-toolkit
total 0
lrwxr-xr-x  1 frankie  staff    95B 12 24 15:40 preload -> ../.pnpm/@electron-toolkit+preload@3.0.0_electron@28.1.0/node_modules/@electron-toolkit/preload
lrwxr-xr-x  1 frankie  staff    91B 12 24 15:40 utils -> ../.pnpm/@electron-toolkit+utils@3.0.0_electron@28.1.0/node_modules/@electron-toolkit/utils

这个路径下,@electron-toolkit 是空目录。

../.pnpm/@electron-toolkit+preload@3.0.0_electron@28.1.0/node_modules/@electron-toolkit

附上:

{
  "name": "menu-bar-tool",
  "version": "0.0.1",
  "main": "./dist/main/index.js",
  "scripts": {
    "format": "prettier --write . --cache",
    "lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --cache",
    "tsc:node": "tsc --noEmit -p tsconfig.node.json --composite false",
    "tsc:web": "tsc --noEmit -p tsconfig.web.json --composite false",
    "tsc": "pnpm run tsc:node && pnpm run tsc:web",
    "start": "electron-vite preview --outDir=dist",
    "dev": "electron-vite dev --outDir=dist",
    "package": "pnpm run tsc && electron-vite build --outDir=dist && electron-forge package",
    "make": "pnpm run tsc && electron-vite build --outDir=dist && electron-forge make"
  },
  "dependencies": {
    "@electron-toolkit/preload": "3.0.0",
    "@electron-toolkit/utils": "3.0.0",
    "electron-updater": "6.1.7"
  },
  "devDependencies": {
    "@electron-forge/cli": "7.2.0",
    "@electron-forge/maker-deb": "7.2.0",
    "@electron-forge/maker-rpm": "7.2.0",
    "@electron-forge/maker-squirrel": "7.2.0",
    "@electron-forge/maker-zip": "7.2.0",
    "@electron-toolkit/eslint-config-prettier": "2.0.0",
    "@electron-toolkit/eslint-config-ts": "1.0.1",
    "@electron-toolkit/tsconfig": "1.0.1",
    "@types/node": "20.10.5",
    "@types/react": "18.2.45",
    "@types/react-dom": "18.2.18",
    "@vitejs/plugin-react": "4.2.1",
    "electron": "28.1.0",
    "electron-vite": "2.0.0-beta.2",
    "eslint": "8.56.0",
    "eslint-plugin-react": "7.33.2",
    "prettier": "3.1.1",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "typescript": "5.3.3",
    "vite": "5.0.10"
  }
}

麻烦看看,谢谢~

Electron-Vite Version

2.0.0-beta.2

Electron Version

28.1.0

Vite Version

5.0.10

Validations

alex8088 commented 10 months ago

pnpm问题,你插件故障排除章节了解相关处理方案。https://cn.electron-vite.org/guide/troubleshooting#a-javascript-error-occurred-in-the-main-process-error-cannot-find-module-xxx

toFrankie commented 10 months ago

pnpm问题,你插件故障排除章节了解相关处理方案。https://cn.electron-vite.org/guide/troubleshooting#a-javascript-error-occurred-in-the-main-process-error-cannot-find-module-xxx

根据指引,看起来 .npmrc 没问题,如下:

ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/
shamefully-hoist=true
save-exact=true

试过移除 pnpm-lock.yamlnode_modules 重新 install 也不行。

我的仓库在这里,麻烦帮忙看看,谢谢~

alex8088 commented 10 months ago

建议你用npm试一试

Super1Windcloud commented 3 weeks ago

软链接的问题,