electron-builder
electron-builder copied to clipboard
Does not work with NPM workspaces
- Electron-Builder Version: 23.3.3
- Node Version: v18.3.0
-
Electron Version: 20.1.0
-
Electron Type (current, beta, nightly): current
- Target: win32 x64
electron builder does not work in npm workspace it deletes app-builder-bin during "installing production dependencies" and then throws error:
• packaging platform=win32 arch=x64 electron=20.1.0 appOutDir=dist\win-unpacked
The system cannot find the path specified.
⨯ spawn C:\Users\user\dev\test-workspace\node_modules\app-builder-bin\win\x64\app-builder.exe ENOENT
also it deletes more packages from node_modules, so next run throws
'electron-builder' is not recognized as an internal or external command
Reproduction:
npm run build -w a
in test-workspace.zip
For me, i just get stuck at installing production dependencies
but the behavior is the same as above.
However, it's working with electron-builder version 22 !
I am having the same or similar problem and found it started happening with npm 8.5.0 (node 16.14.1) because when I downgrade to 8.3.1 (that came with node 16.14.1) while keeping a higher node version, it works. Npm changelog says something about workspaces but I am not sure if its related.
Try to add build option below in your package.json
which has main
entry for electron app:
{
"main": "build/electron/main.js",
...,
"build": {
...,
"npmRebuild": false
}
}
Confirmed that setting npmRebuild
to false
works for my project, but I suspect it is not a universal workaround.
It looks like this code is where the installing production dependencies happens:
https://github.com/electron-userland/electron-builder/blob/01c679107435c6afd0b2de8c44d3f140d20c5577/packages/app-builder-lib/src/util/yarn.ts#L86-L120
It seems to be running node install --production
. I'm guessing that this command is deleting dependencies needed by electron-builder, including the mentioned app-builder-bin.
Setting npmRebuild to false works for me, but I worry disable rebuild may break native dependencies;
Another problem is when depend on a non-exact electron version like ^23.1.0
, it can't find installed electron package and will throw.
It should use require.resolve() or require.resolve.paths() to search packages and not assume in {pwd}/node_modules
I look into the code and figure out that create an empty node_module directory on the specific project where electron-builds solve my issue here. npm rebuild works fine in my case.
See https://github.com/MuhammedKalkan/OpenLens/blob/c4b099462f9e4cdf405d02993a40e5563278bfd1/.github/workflows/main.yml#L47-L49 for a living example.
electron-builder checks, if there is an node_modules dir on the current dir
https://github.com/electron-userland/electron-builder/blob/80a3ae857b9305aff1774e1b2b932601af50231b/packages/app-builder-lib/src/util/yarn.ts#L11-L16
and if not, it just runs npm install again which may not work in npm workspace
scenarios.
An alternative solution is npmRebuild=false
and postinstall: "electron-rebuild"
. This is, what this project is using, however it will not work in cross-compile scenarios.
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.
still an issue
Yes, still an issue: having to create an empty 'node_modules' folder on every workspace and having to fix the version of Electron on package.json
is very annoying...
Very intereesting.
Is there a proper way to detect if we're in a npm workspace and can discern that dependencies are already installed?
Very intereesting.
Is there a proper way to detect if we're in a npm workspace and can discern that dependencies are already installed?
getElectronVersionFromInstalled(projectDir)
is trying to implement its own package resolution algorithm which probably is not a good idea. A better solution could be:
cd ${projectDir}
node -p "require.resolve('electron')"
(…or node -p "import.meta.resolve('electron')"
if project is a module.)
I'm wondering if I could just copy this implementation. https://github.com/electron/rebuild/blob/main/src/electron-locator.ts
It is important that the resolve()
takes place in the context of the electron project, not in the context of the electron-builder itself.
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.
not stale
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.
still not stale
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.
still not stale
still not stale