The expected behavior is that electron-forge should work as-intended no matter the version of npm with which it is being executed.
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.
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.
I think this would be fixed if the webpack dependency in the plugin were moved to peerDependencies but don't have the bandwidth today to do a fork-and-test.
I'm going to downgrade to npm6 until we can track down what's going on here with 7.
Possibly related to this change in NPM?
Peer dependencies
Automatically installing peer dependencies is an exciting new feature introduced in npm 7. In previous versions of npm (4-6), peer dependencies conflicts presented a warning that versions were not compatible, but would still install dependencies without an error. npm 7 will block installations if an upstream dependency conflict is present that cannot be automatically resolved.
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).
Could you confirm if that happens with my PR #2164 ? I am not sure what need to be change for npm 7.
I mainly use yarn these days until npm/workspaces land on LTS.
npm install --legacy-peer-deps
is your friend
The Webpack plugin uses Webpack 5 as of beta 56.
Most helpful comment
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-appwith 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).