Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:9222 - angularjs

I am trying to debugg my angular code with vscode but doesnt work.
Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:9222

I'm not sure you still need it, but I found the solution, since I was facing the same issue myself.
You must launch Chrome with remote debugging enabled in order for the extension to attach to it.
Windows
Right click the Chrome shortcut, and select properties
In the "target" field, append --remote-debugging-port=9222
Or in a command prompt, execute /chrome.exe --remote-debugging-port=9222
OS X
In a terminal, execute /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
Linux
In a terminal, launch google-chrome --remote-debugging-port=9222
I've found this info on the vs code chrome extension's github:
https://github.com/Microsoft/vscode-chrome-debug
Note - If you have already running instances of Chrome. Close them first before opening the updated Chrome window. Ref:- https://github.com/Microsoft/vscode-chrome-debug/issues/111

I got this error because I forgot to close the chrometabs from the previous time the application ran.
Just close those tabs and you are up and running again.

If you running this application in windows, and show you this message, try just restart your machine.
This works for me!

Add-on to the details added by digaomatias
Note: Stop already running Chrome instances/tabs before opening the updated Chrome window.
Reference from Github.

I was able to resolve this issue by stopping the debugger, closing all of my running Chrome windows, and then re-starting the debugger. Note that I'm using IIS Express.

To test and debug in vs code with angular and karma here is a solution,
angular test case to work you have to make a setting in 2 files,
1. Karm.conf.json ( this is a file that set your karma test runner.
2. LaunchSetting.json ( this is file used by your Chome Debugger extension in vs code)
So always first you have to run your karma test runner, on that port and then you can attach debugger on running port.
Step 1) Setup Karma.conf.json,
open default file created by cli,
you got something like this,
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
if you run ng test, you see in console you got some info like is Chrome is running, as well a page will open in browser with http://localhost:9876,
Now time to add headlesschrome with port 9222,
inside config.set, add this,
customLaunchers:{
ChromeHeadless:{
base:'Chrome',
flags:[
'--headless',
'--disable-gpu',
'--no-sandbox',
// Without a remote debugging port, Google Chrome exits immediately.
'--remote-debugging-port=9222',
]
}
}
and now go and add to the browser array ChoromeHeadless, so updated array will look like this, browsers: ['Chrome','ChromeHeadless'],
now run ng test you got in console chrome and chrome headless both running,
Step 2) Time to set up your launcher, to debug on 9222, debug to work you need sourcmap creation to work properly, that is important,
so for same to work just copy-paste config setting from below configuration array to your launchsetting.json configuration array as new config,
configurations: [
{
"name": "Attach to Chrome, with sourcemaps",
"type": "chrome",
"request": "attach",
"port": 9222,
"webRoot": "${workspaceFolder}",
"sourceMapPathOverrides": {
"*": "${webRoot}/*",
},
"sourceMaps": true,
}
]
run ng test, and then go to debugger choose the config we add, your debugger working,
if you using npm run test, then make sure in your package.config where you define a run test, you have not set source map to false, if not then you can set debugger with,
npm run test as well.

Simply close the visual studio and open it again. It has solved my problem

I updated the Visual Studio Code to the latest version, the issue got resolved.

It's a issue about the debugger Browser. I solved it like this:
Install VS Code add in Microsoft Edge Tools for VS Code
Create a lauch config as:
{
"name": "Launch Microsoft Edge and open the Edge DevTools",
"request": "launch",
"type": "vscode-edge-devtools.debug",
"url": "https://localhost:3000/taskpane.html?_host_Info=Excel$Win32$16.01$en-US$$$$0",
"port": 9222,
}
Microsoft Edge Tools for VS Code
Then F5 start to debug.

Go to Tools => Options => Debug => General => and uncheck "Enable JavaScript debugging for Asp.Net (Chrome and IE)

Use like this:
{
"name": "Launch index.html",
"type": "chrome",
"request": "launch",
"file": "${workspaceRoot}/index.html",
"userDataDir": "${workspaceRoot}/out/chrome",
"runtimeExecutable": "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
}

Related

Error Debugging in VS Code: Cannot connect to the target at localhost:3000: could not find any debuggable target

I have an application with React on frontend and .Net Core on backend and i am trying to debug my react frontend, without extensions and attaching to the process, but i am getting the message error bellow:
Cannot connect to the target at localhost:3000: Could not connect to debug target at http:localhost:3000: Could not find any debuggable target.
I'm using this launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug FrontEnd",
"port": 3000,
"request": "attach",
"type": "chrome",
"webRoot": "${workspaceFolder}"
},
{
"name": "Debug BackEnd",
"type": "coreclr",
"request": "attach"
}
]
}
I start my frontend using npm start witch is basically react-scripts start.
Obs.: Iḿ using opera browser.
I found a workaround.
This problem only occurs when I run with sudo npm start.
When running it with just npm start I got this message:
"Unhandled exception. System.IO.IOException: The configured user limit (128) on the number of inotify instances has been reached, or the per-process limit on the number of open file descriptors has been reached."
So I solved it increasing the fs.inotify.max_user_instances with this command:
echo fs.inotify.max_user_instances=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
I found this solution by the answer of #Creak . To see more details, click this link
After a search, all I could found was this issue.
Although Opera is now based on Chromium, it's not possible to debug it using VSCode yet. Maybe someone can come with a kind of workaround for it.

binding.pry not works with command bin/dev

binding.pry not works(console input not available) if i start the server with bin/dev command. It only works with bin/rails s command.
I understand it has something to do with foreman and Procfile.dev, but I don't know how.
Is this a bug or is it supposed to be like this?
A popular approach is to use pry-remote which is useful in some ways I didn't expect: https://github.com/Mon-Ouie/pry-remote.
pry-remote opens a remote terminal, so where you drop your debugger line (binding.remote_pry in the case of pry-remote), you'll open another terminal and enter the debugging session by calling pry-remote in your shell.
I get this is a bit more complicated, I got used to it, and was able to get away from the noise logged by other process with Foreman.
I use rdbg + vscode remote debug and it works fine.
Update Procfile.dev like this to run rdbg with rails server and set a socket file
web: rdbg --command --nonstop --open=vscode --sock_path=tmp/sockets/rdbg.socket -- bundle exec bin/rails server
Install VSCode Ruby rdbg Debugger, configure launch.json like this
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to rdbg Process",
"type": "rdbg",
"request": "attach",
"debugPort": "${workspaceRoot}/tmp/sockets/rdbg.socket",
},
]
}
Now, VSCode will launching with debugger enable while you run bin/dev, or you can run debugger in vscode by F5 anytime

Setting up VSCode with xdebug: pathMapping

I am trying to set up debugging in VSCode and have run into a bit of a challenge. I typed the path to the localSourceRoot but Intellisense is telling me that it is deprecated and I should use pathMapping instead.
I am a newbie and don't know how to properly set that up. If someone could explain to me the variables and/or attributes pathMapping is requesting I would be forever in your debt.
My system info is as follows:
PHP version: 5.524
xdebug version: 2.2.5
OS Windows 8.1
Using Desktop Server version: 3.8.5
I checked the phpinfo() and it shows Xdebug in the file so I know that it is installed. The launch.json file is pretty basic with port 9000 and all of that. I just need to get that darned pathMapping thing done.
Thanks for any and all help.
I guess you're using the PHP debug extension ?
https://github.com/felixfbecker/vscode-php-debug
The README.md says the following:
Remote Host Debugging
To debug a running application on a remote host, you need to tell XDebug to connect to a different IP than localhost. This can either be done by setting xdebug.remote_host to your IP or by setting xdebug.remote_connect_back = 1 to make XDebug always connect back to the machine who did the web request. The latter is the only setting that supports multiple users debugging the same server and "just works" for web projects. Again, please see the XDebug documentation on the subject for more information.
To make VS Code map the files on the server to the right files on your local machine, you have to set the pathMappings settings in your launch.json. Example:
// server -> local
"pathMappings": {
"/var/www/html": "${workspaceRoot}/www",
"/app": "${workspaceRoot}/app"
}
Please also note that setting any of the CLI debugging options will not work with remote host debugging, because the script is always launched locally. If you want to debug a CLI script on a remote host, you need to launch it manually from the command line.
Thus is as much a reference to myself as well as others who might find this helpful. I am running VSCODE with xdebug and drupalvm and the following works for me after setting the following in php.ini
php_xdebug_idekey: VSCODE
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/var/www/drupalvm/drupal": "${workspaceRoot}/drupal",
},
"log": true
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}

Run AngularJS Tutorial with VSCode

I was hoping to try VSCode on the AngularJS tutorial, say step 1, and get debugging and building working.
I was able to get it running, but it's a bit of a hack and VSCode doesn't like it.
{
"version": "0.1.0",
// List of configurations. Add new configurations or edit existing ones.
// ONLY "node" and "mono" are supported, change "type" to switch.
"configurations": [
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Launch app.js",
// Type of configuration. Possible values: "node", "mono".
"type": "node",
// Workspace relative or absolute path to the program.
"program": "app\\js\\app.js",
// Automatically stop program after launch.
"stopOnEntry": true,
// Command line arguments passed to the program.
"args": [],
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
"cwd": ".",
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
"runtimeExecutable": "run.bat",
// Environment variables passed to the program.
"env": { }
},
{
"name": "Attach",
"type": "node",
// TCP/IP address. Default is "localhost".
"address": "localhost",
// Port to attach to.
"port": 5858
}
]
}
I get an "Error Connection failed" even though it is actually running in a separate command prompt window.
Is there a way to for VSCode to debug a simple application like this that only uses package.json start like this:
"start": "http-server -a 0.0.0.0 -p 8000"
Thanks,
Derek
Visual Studio Code supports only Node and Mono debugging, it does not support debugging client JavaScript in the browser.
If you want debug Javascript in the browser, use the browser tools. If you want try out node.js debugging support in VSCode. Start with a sample node.js or express app, then follow the direction in Visual Studio Code website on setting up debugging.
If you would like to see Visual Studio Code supporting debugging, you can vote it up in user voice.

How can I debug a PHP CLI script with xdebug?

I haven't quite figured this out. EVERY piece of documentation I've found covers how to use xdebug to debug scripts running in Apache. I need to debug a php CLI script.
So, for instance, how do I pass the XDEBUG_SESSION_START variable in to get xdebug to kick on?
I'm specifically trying to debug a CakePHP shell. So if anyone has any additional insight into that I'd be very appreciative.
Thanks.
There is a couple of notes about that in Xdebug's manual, like, for instance (quoting) :
export XDEBUG_CONFIG="idekey=session_name"
php myscript.php
If you are using Eclipse PDT to develop and debug your PHP scripts, there is not much difference between Apache or CLI : the configuration lloks quite the same, you just don't have to configure a web server, nor indicate an URL ; instead, you have to indicate the path to the PHP executable.
About the XDEBUG_SESSION_START variable : well, you launch the whole script in "debug-mode", so you don't have any notion of "debugging-session", I'd say.
For instance, here's what Window > Preference > PHP > PHP executables looks like for me right now, and, on the right, what I get when clicking on the Edit button of the first one :
(source: pascal-martin.fr)
(source: pascal-martin.fr)
And the debug configurations window :
(source: pascal-martin.fr)
And launching the debugging: it just works :
(source: pascal-martin.fr)
Hope this helps :-)
Else, what specific problem do you encounter ?
If you're using bash (or similar shell), this little script might come in handy:
alias drush-debug=drd
function drd {
export XDEBUG_CONFIG="idekey=cli_session"
export SERVER_NAME="developer.machine"
export SERVER_PORT="9000"
drush "$#"
unset XDEBUG_CONFIG
unset SERVER_NAME
unset SERVER_PORT
};
or as suggested by the commentators below
alias drd='XDEBUG_CONFIG="idekey=PHPSTORM" drush "$#"'
This way you don't have to manually set and unset the trigger variable each time you want to debug.
simply put the following section to your php.ini
[XDebug]
xdebug.max_nesting_level = 200
xdebug.remote_enable=1
xdebug.remote_port=9000
;xdebug.profiler_enable=1
xdebug.idekey=PHPSTORM
xdebug.remote_autostart=1
and replace PHPSTORM with your ide key
For Windows and Visual Studio Code here's how to proceed:
Download xdebug from https://xdebug.org/download. For example php 7.4 Windows 64bit https://xdebug.org/files/php_xdebug-2.9.5-7.4-vc15-nts-x86_64.dll
Copy the xdebug dll to your php extensions dir (ext).
Add to the end of php.ini
[XDebug]
zend_extension=php_xdebug-2.9.5-7.4-vc15-nts-x86_64.dll
xdebug.remote_enable=1
xdebug.remote_autostart=1
Open VSCode and install https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug
Open the project workspace in VSCode, go to Run tab, click the cogwheel and add these lines
{
"name": "listen CLI",
"type": "php",
"request": "launch",
"port": 9000
},
{
"name": "run CLI",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
Place a break point in the script you want to debug
Select "run CLI" and click "Start Debugging"
Happy debugging!
PHP configuration:
zend_extension=xdebug.so
xdebug.remote_handler=dbgp
xdebug.mode=debug
On my system it is file /etc/php/conf.d/xdebug.ini. Could be in the main php.ini too.
If I want to run a script with XDebug, I pass an environment variable inline:
XDEBUG_SESSION=1 php arguments

Resources