electron / electron/forge

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

Open
#3,562 3 comments 0 reactions 0 assignees View on GitHub
bug plugin/vite
Dominant language
TypeScript
Stars
7.1k
Forks
641
Avg merge
3d 1h
Merged PRs (30d)
30

Description

### Pre-flight checklist

- [X] I have read the [contribution documentation](https://github.com/electron/forge/blob/main/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [code of conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project uses.
- [X] I have searched the issue tracker for a bug that matches the one I want to file, without success.

### 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.

```sh
✗ 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`.

```sh
$ 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](https://github.com/electron/forge/tree/main/packages/template/vite-typescript/tmpl) without any modifications._
In fact, the files by those symlinks exist:

```sh
➜ 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:

```sh
➜ ~ 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!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.