Incompatability between plugin-webpack and NPM7
See original GitHub issuePreflight Checklist
- I have read the contribution documentation for this project.
- I agree to follow the code of conduct that this project follows, as appropriate.
- I have searched the issue tracker for a bug that matches the one I want to file, without success.
Issue Details
- Electron Forge Version:
- 6.0.0-beta.53
- Electron Version:
- 10.1.3
- Operating System:
- Mac OS 10.15.7
- Last Known Working Electron Forge version::
- n/a
Expected Behavior
The expected behavior is that electron-forge should work as-intended no matter the version of npm
with which it is being executed.
Actual Behavior
Because of a change in how dependency resolution is processed as of npm@7
(recently released), electron-forge commands no longer run, at least for my project on my machine.
In these cases, the error reported here occurs - “TypeError: Cannot read property ‘createSnapshot’ of undefined”.
Digging into node_modules
, I can confirm that there is a node_modules/webpack
at version 5 and a /node_modules/@electron-forge/plugin-webpack/node_modules/webpack
at version 4. This duplicate issue is almost surely what is causing the error.
Downgrading to npm@6 fixes the issue.
To Reproduce
- NPM is on a version greater than 7.0.0. In my case, 7.0.2.
- electron-forge is a local dev dependency to the project.
- Some mysterious condition I haven’t yet cornered…
I’m posting this before I’ve found exactly what is causing this issue on this one project, but which fails to reproduce on npm@6 or on a plain npx create-electron-app my-new-app --template=webpack
. My hope is that someone else is running into this and has some of the data I am missing.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:5 (2 by maintainers)
Top GitHub Comments
Possibly related to this change in NPM?
As described, the issue is the webpack 4 dependency within the webpack plugin. Either upgrading to webpack 5 or declaring it as a peer dependency fixes the issue, not sure what the right course of action is since I don’t know my way around the codebase.
The bug occurs when using NPM 7 and generating a project with
create-electron-app
with the webpack (or typescript-webpack) template. To circumvent, switch to NPM 6 (latest node version would be 14.15.5) for generation, then switch back to NPM 7 and it’ll work fine (obviously you need a node version manager).The Webpack plugin uses Webpack 5 as of beta 56.