Skip to content

Debugger launch does not work with npm or yarn workspaces / monorepo #2649

@RandomEngy

Description

@RandomEngy

Pre-flight checklist

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project uses.
  • I have searched the issue tracker for a bug that matches the one I want to file, without success.

Electron Forge version

6.0.0-beta.61

Electron version

16.0.4

Operating system

Windows 11 21H2 22000.376

Last known working Electron Forge version

No response

Expected behavior

The app launches under debug mode with VSCode.

Actual behavior

An unhandled rejection has occurred inside Forge:
node_modules/@electron-forge/cli/dist/util/terminate.js:10
Error: Could not find any Electron packages in devDependencies
at getElectronModuleName (C:\git\Focalist\node_modules@electron-forge\core\src\util\electron-version.ts:62:11)
at getElectronVersion (C:\git\Focalist\node_modules@electron-forge\core\src\util\electron-version.ts:99:23)
at _default (C:\git\Focalist\node_modules@electron-forge\core\src\api\start.ts:52:11)
at C:\git\Focalist\node_modules@electron-forge\cli\src\electron-forge-start.ts:58:19

Steps to reproduce

  1. Set up a repository with NPM workspaces, and the electron project under one subdirectory
  2. Run npm i to install dependencies to node_modules
  3. Add the recommended launch.json setup for debugging to VS code:
{
  "type": "node",
  "request": "launch",
  "name": "Electron Main",
  "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron-forge-vscode-nix",
  "windows": {
    "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron-forge-vscode-win.cmd"
  },
  // runtimeArgs will be passed directly to your Electron application
  "runtimeArgs": [
    "foo",
    "bar"
  ],
  "cwd": "${workspaceFolder}"
}
  1. Launch the app with F5

Additional information

I also tried adding the electron packages to devDependencies in the root package.json and got this error window:

[Window Title]
Error

[Main Instruction]
Error launching app

[Content]
Unable to find Electron app at C:\git\Focalist

Cannot find module 'C:\git\Focalist'
Require stack:
- C:\git\Focalist\node_modules\electron\dist\resources\default_app.asar\main.js

I then changed the cwd to "${workspaceFolder}/electron" (my workspace folder) and VS got into the "debug" mode with the orange status bar, but the electron app didn't launch.

The only workaround I can think of is switching to yarn workspaces: that can prevent hoisting and keep more packages in the app's node_modules, which might let the launch work correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions