electron / forge

:electron: A complete tool for building and publishing Electron applications
https://electronforge.io
MIT License
6.28k stars 487 forks source link

Unable to package app on macOS using vite-typescript + typeorm library #3562

Open ifree92 opened 1 month ago

ifree92 commented 1 month ago

Pre-flight checklist

Electron Forge version

6.4.0, 6.3.1 as well (older version did not test)

Electron version

29.3.0

Operating system

macOS 14.4.1 (tried on Windows, no issues, seems this is specific for macOS)

Last known working Electron Forge version

No response

Expected behavior

The package process should finish without an error and provide a successful macOS build.

Actual behavior

Below is the console output of the npm run package command that ends with an error without a successful build.

✗ npm run package

> electron-experiments-vite-ts@1.0.0 package
> electron-forge package

✔ Checking your system
✔ Preparing to package application
✔ Running packaging hooks
  ✔ Running generateAssets hook
  ✔ Running prePackage hook
    ✔ [plugin-vite] Building vite bundles
❯ Packaging application
  ❯ Packaging for arm64 on darwin
    ✔ Copying files
    ✔ Preparing native dependencies [3s]
    ✖ Finalizing package
      › /var/folders/cx/jfcxhpvd7pdb2q0bw3nzgwd40000gq/T/electron-packager/tmp-aRGLfT/Electron.app/Contents/Resources/app/node_modules/typeorm/node_modules/.bin/glob: file
        "../../../../../../../../../../../../var/folders/cx/jfcxhpvd7pdb2q0bw3nzgwd40000gq/T/electron-packager/tmp-aRGLfT/Electron.app/Contents/Resources/app/node_modules/typeorm/node_modules/glob/dist/esm/bin.mjs"
        links out of the package
◼ Running postPackage hook

The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.
vite v5.2.8 building for production...
vite v5.2.8 building for production...
vite v5.2.8 building for production...
transforming (1) index.html
transforming (1) src/preload.ts
✓ 1 modules transformed.
Generated an empty chunk: "preload".
rendering chunks (1)...
transforming (1) src/main.ts
✓ 1 modules transformed.
rendering chunks (1)...
computing gzip size (0)...
computing gzip size (1)...
.vite/build/preload.js  0.01 kB │ gzip: 0.03 kB
✓ built in 38ms
computing gzip size (0)...
computing gzip size (1)...
.vite/build/main.js  0.50 kB │ gzip: 0.32 kB
✓ built in 39ms
✓ 4 modules transformed.
rendering chunks (1)...
computing gzip size (0)...
computing gzip size (1)...
computing gzip size (2)...
computing gzip size (3)...
.vite/renderer/main_window/index.html                 0.37 kB │ gzip: 0.26 kB
.vite/renderer/main_window/assets/index-CKttBNm8.css  0.14 kB │ gzip: 0.14 kB
.vite/renderer/main_window/assets/index-D8Tcqwow.js   0.79 kB │ gzip: 0.46 kB
✓ built in 46ms

An unhandled rejection has occurred inside Forge:
Error: /var/folders/cx/jfcxhpvd7pdb2q0bw3nzgwd40000gq/T/electron-packager/tmp-aRGLfT/Electron.app/Contents/Resources/app/node_modules/typeorm/node_modules/.bin/glob: file "../../../../../../../../../../../../var/folders/cx/jfcxhpvd7pdb2q0bw3nzgwd40000gq/T/electron-packager/tmp-aRGLfT/Electron.app/Contents/Resources/app/node_modules/typeorm/node_modules/glob/dist/esm/bin.mjs" links out of the package
at Filesystem.insertLink (/Users/ihor.levchenkoedisen.com/Projects/js/electron-experiments-vite-ts/node_modules/@electron/asar/lib/filesystem.js:106:13)
    at handleFile (/Users/ihor.levchenkoedisen.com/Projects/js/electron-experiments-vite-ts/node_modules/@electron/asar/lib/asar.js:132:20)
    at next (/Users/ihor.levchenkoedisen.com/Projects/js/electron-experiments-vite-ts/node_modules/@electron/asar/lib/asar.js:148:11)
    at next (/Users/ihor.levchenkoedisen.com/Projects/js/electron-experiments-vite-ts/node_modules/@electron/asar/lib/asar.js:149:12)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async MacApp.asarApp (/Users/ihor.levchenkoedisen.com/Projects/js/electron-experiments-vite-ts/node_modules/@electron/packager/src/platform.ts:245:5)
    at async MacApp.buildApp (/Users/ihor.levchenkoedisen.com/Projects/js/electron-experiments-vite-ts/node_modules/@electron/packager/src/platform.ts:150:5)
    at async MacApp.initialize (/Users/ihor.levchenkoedisen.com/Projects/js/electron-experiments-vite-ts/node_modules/@electron/packager/src/platform.ts:141:7)
    at async MacApp.create (/Users/ihor.levchenkoedisen.com/Projects/js/electron-experiments-vite-ts/node_modules/@electron/packager/src/mac.ts:435:5)
    at async Promise.all (index 0)
    at async packager (/Users/ihor.levchenkoedisen.com/Projects/js/electron-experiments-vite-ts/node_modules/@electron/packager/src/packager.ts:246:20)

Steps to reproduce

I've been using NodeJS 20.9.0, NPM version is 10.1.0.

$ npm init electron-app@latest electron-experiments-vite-ts -- --template=vite-typescript
$ cd electron-experiments-vite-ts
$ npm i -S typeorm
$ npm run package

You will get an error posted in "Actual Behavior" section. I even have no idea why is it happening. But once typeorm is removed (npm uninstall typeorm), now the build is successful. Kinda a "special" reaction on the typeorm.

Additional information

I did not specify the config files here, cos it is reproducible using a raw vite-typescript template without any modifications. In fact, the files by those symlinks exist:

➜  electron-experiments-vite-ts git:(main) ✗ ls -l node_modules/typeorm/node_modules/.bin
total 0
lrwxr-xr-x@ 1 ihor.levchenkoedisen.com  staff  24 Apr 11 20:44 glob -> ../glob/dist/esm/bin.mjs
lrwxr-xr-x@ 1 ihor.levchenkoedisen.com  staff  29 Apr 11 20:44 mkdirp -> ../mkdirp/dist/cjs/src/bin.js

➜  electron-experiments-vite-ts git:(main) ✗ ls -l node_modules/typeorm/node_modules/glob/dist/esm | grep bin.mjs
-rwxr-xr-x@ 1 ihor.levchenkoedisen.com  staff   9754 Apr 11 20:44 bin.mjs
-rw-r--r--@ 1 ihor.levchenkoedisen.com  staff  14768 Apr 11 20:44 bin.mjs.map

Even in a temp folder:

➜  ~ ls -l /var/folders/cx/jfcxhpvd7pdb2q0bw3nzgwd40000gq/T/electron-packager/tmp-fiXHPP/Electron.app/Contents/Resources/app/node_modules/typeorm/node_modules/.bin/
total 0
lrwxr-xr-x@ 1 ihor.levchenkoedisen.com  staff  24 Apr 11 20:46 glob -> ../glob/dist/esm/bin.mjs
lrwxr-xr-x@ 1 ihor.levchenkoedisen.com  staff  29 Apr 11 20:46 mkdirp -> ../mkdirp/dist/cjs/src/bin.js

➜  ~ ls -l /var/folders/cx/jfcxhpvd7pdb2q0bw3nzgwd40000gq/T/electron-packager/tmp-fiXHPP/Electron.app/Contents/Resources/app/node_modules/typeorm/node_modules/glob/dist/esm | grep bin.mjs
-rwxr-xr-x@ 1 ihor.levchenkoedisen.com  staff   9754 Apr 11 20:46 bin.mjs
-rw-r--r--@ 1 ihor.levchenkoedisen.com  staff  14768 Apr 11 20:46 bin.mjs.map

Except typeorm, other packages also have symlinks from their .bin folder to the specific JS files:

➜ cd node_modules && find . | grep -i "node_modules/.bin/"
./normalize-package-data/node_modules/.bin/semver
./temp/node_modules/.bin/rimraf
./temp/node_modules/.bin/mkdirp
./eslint-plugin-import/node_modules/.bin/semver
./yarn-or-npm/node_modules/.bin/semver
./yarn-or-npm/node_modules/.bin/which
./typeorm/node_modules/.bin/glob
./typeorm/node_modules/.bin/mkdirp
./execa/node_modules/.bin/semver
./execa/node_modules/.bin/which
./electron/node_modules/.bin/semver
./global-prefix/node_modules/.bin/which
./@electron/get/node_modules/.bin/semver

➜  electron-experiments-vite-ts git:(main) ✗ ls -l node_modules/electron/node_modules/.bin
total 0
lrwxr-xr-x@ 1 ihor.levchenkoedisen.com  staff  23 Apr 11 20:44 semver -> ../semver/bin/semver.js

Probably the issue is mostly related to the @electron/asar behavior, however, it is a part of the template vite-typescript that I'm using, so it is posted here.

NOTE: For the webpack-typescript there is no issue, it works as expected with typeorm. The problem happens only when vite-typescript template is used!

ifree92 commented 1 month ago

Probably, this is the related issue https://github.com/electron/forge/issues/3549