Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug with VSCode #46

Closed
manikantag opened this issue Dec 30, 2016 · 10 comments
Closed

Debug with VSCode #46

manikantag opened this issue Dec 30, 2016 · 10 comments
Labels

Comments

@manikantag
Copy link

manikantag commented Dec 30, 2016

Please describe your issue:
Unable to start/debug the app using VSCode.

Console output when you run electron-forge with the environment variable DEBUG=electron-forge:*. (Instructions on how to do so here. Please include the stack trace if one exists.

With below launch.json configuration,

"configurations": [
	{
	    "name": "Launch Program",
	    "type": "node",
	    "request": "launch",
	    "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd",
	    "program": "${workspaceRoot}/es6-init.js",
	    "cwd": "${workspaceRoot}"
	}
]

I m getting below error:

c:\eapp/node_modules/.bin/electron.cmd --debug-brk=21609 --nolazy es6-init.js 

App threw an error duri
ng load
Error: Cannot fi
nd module 'c:\eapp\--debug-brk=21609'
    at Module._resolveFilename (module.js:455:15)
    at Function.Module._resolveFilename (c:\eapp\node_modules\electron-prebuilt-compile\node_modules\electron\dist\resources\electron.asar\common\reset-search-paths.js:35:12)

With below launch.json configuration,

"configurations": [
	{
	    "name": "Launch Program",
	    "type": "node",
	    "request": "launch",
	    "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-forge.cmd",
	    "cwd": "${workspaceRoot}",
	    "args": [
	        "start"
	    ]
	}
]

I m getting below error:

c:\eapp/node_modules/.bin/electron-forge.cmd --debug-brk=41000 --nolazy start 
√ Checking your System
  error: unknown option `--debug-brk'

What command line arguments are you passing?

Can be seen in above section

What does your config.forge data in package.json look like?

"forge": {
    "make_targets": {
        "win32": ["squirrel"],
        "darwin": ["zip"],
        "linux": ["deb","rpm"]
    },
    "electronPackagerConfig": {
        "ignore": [
            "node_modules/sqlite3/build",
            "node_modules/sqlite3/deps",
            "node_modules/sqlite3/src"
        ]
    },
    "electronWinstallerConfig": {
        "name": "eapp",
        "loadingGif": "./assets/img/install-splash.png",
        "iconUrl": "http://manikanta.com/favicon.ico",
        "setupIcon": "./assets/img/icon.ico",
        "noMsi": true
    },
    "electronInstallerDebian": {},
    "electronInstallerRedhat": {}
}

Can you please let me how to configure properly? Thanks.

@MarshallOfSound
Copy link
Member

error: unknown option `--debug-brk'

This is because electron-forge expects your command to be

electron-forge start --debug-brk=41000 --nolazy

You should go ask on the VS Code repository how to make the node debug arguments appear after your custom arguments (["start"])

@manikantag
Copy link
Author

I've tried the same, but still getting error (ran from cmd prompt):

C:\eapp>electron-forge start --debug-brk=41000
√ Checking your System
- Locating Application
  error: unknown option `--debug-brk'

By the way, thanks for the tip about VSCode. I got some clues from microsoft/vscode#16173.

Below is how I've configured VSCode:

"configurations": [
    {
        "name": "Launch Program",
        "type": "node",
        "request": "launch",
        "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-forge.cmd",
        "port": 41000,
        "runtimeArgs": [
            "start",
            "--debug-brk=41000",
            "--nolazy"
        ],
        "cwd": "${workspaceRoot}"
    }
]

@MarshallOfSound
Copy link
Member

What version of electron forge are you using? The latest version definitely shouldn't throw that error

@manikantag
Copy link
Author

manikantag commented Dec 30, 2016

Now I've switched to 2.2.0, and things are different now.

When I didn't pass --debug-brk switch, app is starting more than one electron process and app window is launching.

c:\eapp>node_modules\.bin\electron-forge.cmd start
√ Checking your System
√ Locating Application
√ Preparing native dependencies 1/1
√ Launching Application

image

But when I pass --debug-brk, only one electron process is starting and no visible window is launched. But the command o/p is same though.

c:\eapp>node_modules\.bin\electron-forge.cmd start --debug-brk=41000
√ Checking your System
√ Locating Application
√ Preparing native dependencies 1/1
√ Launching Application

image

@MarshallOfSound
Copy link
Member

MarshallOfSound commented Dec 30, 2016

I am unfamiliar with the fine art of attaching a debugger to the main Electron process and this isn't really an issue with electron-forge rather a usage question regarding Electron itself which can be summarised as.

"How can I debug the main process of Electron?"

A good guide exists in the Electron repository.

https://github.com/electron/electron/blob/master/docs/tutorial/debugging-main-process-vscode.md

If that guide doesn't work you can ask for help in the Electron community or Slack Channel.

@manikantag
Copy link
Author

I think I m not clear enough. All the above output is from running the app from command line. No VSCode here :)

@MarshallOfSound
Copy link
Member

@manikantag Everything after the word start in that command is simply passed through to the electron command.

c:\eapp>node_modules\.bin\electron-forge.cmd start --debug-brk=41000

Is exactly the same as

c:\eapp>node_modules\.bin\electron.cmd . --debug-brk=41000

Therefore if that command doesn't do what you expect it to do or you can't figure out what the syntax is that you want, you need to ask over at the Electron community / slack areas. The electron-forge issues section hopefully is to remain for forge specific issues 👍

@enlight
Copy link

enlight commented Dec 31, 2016

But when I pass --debug-brk, only one electron process is starting and no visible window is launched.

This is to be expected, --debug-brk means "attach the debugger and pause execution on program entry", so the main process of your app is paused on startup waiting for you to step/continue execution via the debugger. When you do continue execution the main process will then go on and create all the other processes (renderer, GPU, etc.). If you don't want your app to pause on entry then use the --debug flag.

By the way, VSCode debug configurations have a boolean property called stopOnEntry that toggles this --debug-brk flag.

@manikantag
Copy link
Author

@enlight Yeah, I've figured it out. Now I m using 'Attach' mode to run the app. Somehow I m having issues with 'Launch' mode.

@manikantag
Copy link
Author

manikantag commented Dec 31, 2016

All this confusion is because even though I've mentioned --debug=41000, but still electron is starting 5858 as debug port and thus VSCode is not able to attach to the port=41000 specified in launch.json.

Below is the command line args of the app process tree.

Parent node process is having correct command line args: (--debug=41000)
image

Child node process is having incorrect command line args: (--debug 41000) (mind the missing =)
image

Now I've changed to port=5858 in VSCode's launch.json and is attaching properly.

But I m not sure why it is like this :(

dsanders11 pushed a commit that referenced this issue Jan 14, 2023
test: Enfore a stricter code style
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants