electron / forge

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

`plugin-electronegativity` error: "warn: Couldn't detect Electron version, assuming v0.1.0" #2818

Closed guizmaii closed 2 years ago

guizmaii commented 2 years ago

Pre-flight checklist

Electron Forge version

6.0.0-beta.63

Electron version

v18.1.0

Operating system

Ubuntu 20.04.4 / macOS 11.6.5 / Microsoft Windows Server 2022 10.0.20348

Last known working Electron Forge version

No response

Expected behavior

The Electron version must be auto-detected

Actual behavior

I configured the plugin-electronegativity in a brand new generated Electron+TS+Wepback project (thanks to https://www.electronforge.io/templates/typescript-+-webpack-template), following the plugin doc: https://www.electronforge.io/config/plugins/electronegativity

In my CI, running on Mac, Windows and Linux, when I run yarn make I have the following error:

warn: Couldn't detect Electron version, assuming v0.1.0. Defaults have probably changed for your actual version, please check manually.

Steps to reproduce

Additional information

No response

erikian commented 2 years ago

The Webpack plugin modifies the original package.json, setting devDependencies (as well as dependencies/optionalDependencies/peerDependencies) to an empty object here: https://github.com/electron/forge/blob/1f45e2ca701ec117df932f38e7fe808bdd832e74/packages/plugin/webpack/src/WebpackPlugin.ts#L241-L244

When @doyensec/electronegativity attempts to read the Electron version from devDependencies, it finds none, hence the error.

I believe this could be fixed by simply not modifying the original package.json file. While removing dependencies from the distributed package.json can be desirable, plugins shouldn't really introduce any side effects like this one.

This behavior seems to exist just as an additional measure to prevent the whole node_modules directory to be packaged, as described in https://github.com/electron-userland/electron-forge/issues/593#issuecomment-430102069. But since the plugin already ignores anything outside the .webpack directory and does not call npm install, using the original package.json should be safe enough.