forge: vscode-nix script cannot find the other executables

Preflight Checklist

Issue Details

  • Electron Forge Version:
    • 6.0.0-beta.47
  • Electron Version:
    • v7.1.7
  • Operating System:
    • macOS 10.15.2

Expected Behavior

Using the launch configuration from https://www.electronforge.io/advanced/debugging in VS Code enables debugging for the new application.

Actual Behavior

The launch configuration errors with:

/Users/liamdawson/w/orcharduml/node_modules/.bin/electron-forge-vscode-nix --inspect-brk=35706 
internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module '/Users/liamdawson/w/@electron-forge/cli/dist/electron-forge-start'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

To Reproduce

  • yarn v1.21.1
  • npm v6.13.4
  • node v10.16.3

Additional Information

I’m guessing it’s related to something about package nesting and/or symlinks?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 6
  • Comments: 15 (1 by maintainers)

Commits related to this issue

Most upvoted comments

to fix it the electron-forge-vscode-nix file must be change from

#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

ARGS=$@
ARGS=${ARGS// /\~ \~}

node $DIR/../../../@electron-forge/cli/dist/electron-forge-start --vscode -- \~$ARGS\~

to

#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

ARGS=$@
ARGS=${ARGS// /\~ \~}

node $DIR/../@electron-forge/cli/dist/electron-forge-start --vscode -- \~$ARGS\~

Yet another workaround or solution for debugging:

In your .vscode/ launch.json

{
    "version": "0.2.0",
    "configurations": [
        { 
            "type": "node",
            "request": "launch",
            "name": "Electron Main",
            "runtimeExecutable": "npm",
            "runtimeArgs": ["run-script", "debug"],
            "cwd": "${workspaceFolder}"
        }
    ]
}

and another script in package.json:

scripts: {
    "debug": "electron-forge start --vscode",
…

(I don’t need any extra arguments, so I have not looked into that topic).

I’m having this problem as well using electron-forge 6.1.1 with MacOS 12.2.1.

I tried using the original VSCode launch config from the Electron Forge Docs:

{
  "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}"
}

I solved it by simply pointing the runtimeExecutable directly at the Bash script’s true location rather than the symlink to the same file that exists in .bin/electron-forge-vscode-nix

- "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron-forge-vscode-nix",
+ "runtimeExecutable": "${workspaceFolder}/node_modules/@electron-forge/cli/script/vscode.sh",

The problem seems related to the expectation that this line from the script gets the location of th script gets the true location, but instead it gets the location of the symlink.

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

This is still an issue as of electron-forge @ 6.0.0-beta.61

Currently, patching this manually. Kinda brutal. Lets fix?

same issue. The problem is Error: Cannot find module '/Users/liamdawson/w/@electron-forge/cli/dist/electron-forge-start' but it missing node_modules in path 🤔

@kresli thank you for this patch which worked with electron-forge 6.0.0-beta.61 on macOS with VSCode 1.62.3.

As someone who is new to Electron in general this was a really confusing and unfortunate issue for beginners.