I typically only ran Python and C++ code. When running Python Code, it would drop down a simply menu, such as this.
It would drop this down then you would click enter and boom it would run
But then I randomly ran a console.log("Hello World") JavaScript program. It dropped down a menu and I selected something like "Node.js" or whatever.
Anyway now when I go to run code, it opens in something called the "JavaScript Debug Terminal". The code never ran and you just had to manually open the file and run it. Later I went to the run and debug page and added a configuration to a launch.json file, where I added a Python Config:
{
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
Now when I run Python Code it runs in something called the "Python Debug Console". Can someone tell me how to revert this to how it was in the factor settings
It appears that you're running the python file in debug mode. If you want to run python normally you can right-click anywhere in the file and select run python file in terminal.
For more information on running python files, you can look at https://code.visualstudio.com/docs/python/python-tutorial.
Related
After the last update of VS Code to version 1.69.2 i am not able to debug my nodejs - express, project. I am getting unbound breakpoints when i am adding them. My launch.json file :
{
"configurations": [
{
"name": "Attach by Process ID",
"processId": "${command:PickProcess}",
"request": "attach",
"skipFiles": [
"<node_internals>/**"
],
"type": "node",
"sourceMaps": false
}
]
}
When i am trying to "troubleshoot the launch configuration" i am getting the error message from vs code : "it looks like your degug session has already ended......" but it is not, it is active.
In my project i am using nodejs - express - javascript mostly (no Typescript thats why i set sourceMaps to false).
I am starting my project with the command :
node --inspect sever.js
and after that i attach by procces the debugger ( to default 127.0.0.1:9229).
Can anyone help me to solve this problem? What has change after the last update and i can't use the degugging of VS Code?
Thanks a lot.
Download a previous version.
Also, disable auto updates from Settings -> Update.
https://code.visualstudio.com/updates/v1_68
I am new to VS Code and JavaScript, and I am trying to make a simple app using Vite and Svelte, but I have a problem which I can't seem to resolve. (My code is currently just the default code given when a new project is created; I haven't changed it at all.)
When I run my app through Windows Terminal (by navigating to the project root directory and running npx vite dev), the app runs fine and my browser can connect to localhost:3000.
However, when I press on either:
Run > Start Debugging, or
Run > Run Without Debugging
in Visual Studio Code, it opens up Chrome to localhost:3000 but I just see localhost refused to connect. I think VS Code is never actually running the command npx vite dev, but I don't know how to change this.
When I open up .vscode/launch.json, I see this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug with Chrome",
"type": "pwa-chrome",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}",
}
]
}
And I am not sure what I should add here to get this to work. Any help would be appreciated, and sorry if this is a bit of a stupid question, but I couldn't fund any help searching Google or SO.
EDIT:
I have almost got this working by adding a preLaunchTask, but now chrome no longer automatically opens when I start debugging, so I might as well just run npm: dev on its own.
Here is .vscode/launch.json now:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug with Chrome",
"type": "pwa-chrome",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}",
"preLaunchTask": "npm: dev"
}
]
}
I think this might be because the npm: dev task (which effectively runs npx vite dev) is blocking, and only finishes when I press the stop button (or double-click ctrl+c), so chrome is not opened because VS Code thinks the pre-launch task is still running.
If there any way I can tell VS Code to open Chrome while continuing to run npm: dev?
Here's the VSCode way to start the Vite Dev server (npx vite) and then automatically open Chrome and attach a debug session to it.
// launch.json
{
// 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": "Launch Vite DEV server",
"request": "launch",
"runtimeExecutable": "npx",
"runtimeArgs": [
"vite",
],
"type": "node",
"serverReadyAction": {
"action": "debugWithChrome",
"pattern": "Local: http://localhost:([0-9]+)",
"uriFormat": "http://localhost:%s"
}
},
],
}
Many things can be customized in the launch.json. I recommend you to read the documentation linked above.
The "magic" happends in "serverReadyAction" where you set the "action" to "debugWithChrome" to open chrome.
The "pattern" is a regex used to capture the port on which the server have been launched.
Finally, you add the port to the URL in the "uriFormat" by using %s. %s represent the capture done with the regex in "pattern"
Instead of having it run npx vite dev (which is the npm: dev task), have it run npx vite dev --open :)
enter image description here
I just started to learn JS and was trying to printout "Hello,World" the basic.
However,
[Running] and [Done] messages were printed properly but not for the text "Hello,World".
According to other "hello,world" sources from tutorials and documents, "console" was colored with different color except white. Is this point related to this printout problem?
You can debug with external terminal by configuring launch.json (you need to place your file inside a folder to do configuration).
Go to Debug -> Open Configurations
Add "console": "externalTerminal" to your launch.json:
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/t.js",
"console": "externalTerminal"
}
]
Try Debugging and VSCode will debug your output on a separate terminal.
you need to switch your terminal tab to see the console , its the last one normally
Open terminal and type node filename.js and run it
Make sure that you add a semicolon (;) at the end of the statement and that you save the file before running it again.
console.log('Hello World');
Microsoft has just released the new Visual Studio Code for the Mac OS X platform. It supports TypeScript, in that one can get autocomplete and error reporting for TypeScript code.
My question: How can we compile a TypeScript file (to produce the corresponding JavaScript file) from within Visual Studio Code? I have created a default tsconfig.json file as recommended, with just {}, and have tried invoking shift+command+B but this does not produce an updated JavaScript file.
You will need to set up a task to do this.
I apologise in advance if I get the short-cuts a bit wrong as I am sat using a different operating system. For anyone using Windows, it will be CTRL - I think the OSX version just means using CMD instead.
If you press CTRL + SHIFT + P, you should get an action menu appear that allows you to search all commands.
Type Configure Task Runner. If you don't already have one, this will create a tasks.json file in a settings folder for you. Otherwise, it will open the existing tasks.json file.
You can uncomment the TypeScript task that is built in - it looks like this (my main file is app.ts, the default in this file is HelloWorld.ts):
// A task runner that calls the Typescipt compiler (tsc) and
// Compiles a HelloWorld.ts program
{
"version": "0.1.0",
// The command is tsc.
"command": "tsc",
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
// Under windows use tsc.exe. This ensures we don't need a shell.
"windows": {
"command": "tsc.exe"
},
// args is the HelloWorld program to compile.
"args": ["app.ts"],
// use the standard tsc problem matcher to find compile problems
// in the output.
"problemMatcher": "$tsc"
}
You can then this task on demand using CTRL + SHIFT + B.
If you have multiple tasks defined, you can use CTRL + E and type task (note the space after "task") and it will give you a list of all tasks for you to choose from.
Your hands don't need to leave the keyboard for any of this!
Lastly... if you are still getting nothing, check this icon at the bottom of the window as you may have a compiler error... (the icons below are showing one error - click on it in your editor for details).
I had faced the same issue with the tsc transpiler (since it compiles a source code from one format to another) not generating the ".js" file.
Workaround:
Try executing the following command in your Windows Command Prompt (cmd.exe - Run as Administrator):
tsc test.ts
Ensure that you are in the right folder path or else provide the absolute path for the ".ts" file
Hopefully, it should generate the ".js" file in the same folder as the ".ts" file.
Now that the ".js" file is generated, inorder to avoid executing the above command everytime you make a change, you can execute an auto-transpilation watch command in tsc.
To perform an auto-transpilation for the ".ts" file, try running the following command:
tsc test.ts --watch
Now if you go back to your ".ts" file and make changes and hit Save, it will perform an auto-transpilation and update your ".js" file instantly. Remember to keep the command prompt running.
I am yet to explore the reason as to why the tsc transpiler is not working on Visual Studio Code's Ctrl + Shift + B keypress, but my best guess would be an issue with the tsc version used by my Visual Studio Code installation or the environment PATH variables defined or npm installed a different tsc version.. reasons could be multiple.
Output:
But for those who want to get things done quickly, i hope this workaround helps.
You need a tsconfig.json file to define all options for the TypeScript Compiler, and a tasks.json file to set the compiler options.
tsconfig.json
{
"compilerOptions": {
"target": "ES5",
"module": "amd",
"sourceMap": false
}
}
tasks.json ... See the line "args" with ${file} to compile the opened file.
{
"version": "0.1.0",
// The command is tsc.
"command": "tsc",
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
// Under windows use tsc.exe. This ensures we don't need a shell.
"windows": {
"command": "tsc.exe"
},
// args is the HelloWorld program to compile.
"args": ["${file}"],
// Use the standard tsc problem matcher to find compile problems
// in the output.
"problemMatcher": "$tsc"
}
More info: http://blogs.msdn.com/b/typescript/archive/2015/04/30/using-typescript-in-visual-studio-code.aspx
I found a solution that worked on the Mac. In the args line, I put the full path name for the TypeScript file that I wanted to compile. Then, launching a build using CMD + SHIFT + B did successfully run the tsc compiler and did successfully generate the corresponding JavaScript file.
I would like to be able to use one shortcut for running and killing node process including showing and hiding build window as needed.
I press ctrl + B:
Show Build Window
Run Node process
I press ctrl + B again:
Kill Node process
Close Build Window.
I also need kill signal to be sent so that I can read it in node application and perform couple of actions prior to the exiting.
Currently the first part of what I need is working but to close node app I need to ctrl + shift + B and then hit esc to close build window.
Is this possible and if it is, how?
EDIT 1 (18.09.14)
Made a sublime text plugin that does exactly what I described above. Currently tested on ST3 (Windows and Linux). Only issue currently is that on windows platform, your node script wont get proper kill signal (SIGINT or something similar) for pre-exit proecedures. I use sublime texts own console for io procedures - very convenient. Might release plugin soon if people feel interested in it.
One approach would be to, in your build system, first kill the running node process & if that's not successful pass the current file to node. So your node.sublime-build might look like this:
{
"cmd": [ "killall node || node \"$file\"" ],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.js",
"shell": true
}
Sublime only allows one command which is passed multiple arguments, so something like "cmd": [ "killall node ||", "node", "$file"] wasn't working, though I think it worked previously in Sublime 2. Thus the need to wrap $file in escaped quotes, because otherwise the command will fail if the path to $file has a space in it. Also, || is pivotal here, because killall exits with a status of 1 (error) if there were no processes to kill, so the first time it will run node but the second time it won't.
Note that, since we're working in the shell here, this is platform-specific. I don't know how to do the equivalent of || on Windows, but you'd just need something like this:
{
"cmd": [ "killall node || node \"$file\"" ],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.js",
"shell": true
"windows": {
"cmd": [ "insert whatever works here..." ]
}
}
One big limitation is that this kills all running node processes; that'd be annoying if you want to keep something running in the background. If someone knows how to target a specific node process in a single command, please add to my answer.
Secondly, you could wrap the cmd in a bash script, which would make it easier to do multiple things like kill a particular process. Then the cmd array would be [ "bash", "name-of-script.sh" ]. Using lsof it would be rather easy to get the particular node process that's running your current file. You could also use bash -c as the command and then paste a whole script into the second element of the cmd array.
Hope that helps. I'm missing one piece of your requirement: ESC will still be needed to close the build window. Not sure what else can be done there without writing a Sublime plug-in.
Anyway, I fix it in windows like that
{
"shell": true,
"windows": {
"cmd": "(TASKKILL /F /IM node.exe || 1)&& node \"$file\""
}
}
I did it the same way but not checking for any file other than .js files
{
"cmd": [ "killall node || node \"$file\"" ],
"selector": "*.js",
"shell": true
"windows": {
"cmd": "(TASKKILL /F /IM node.exe || 1)&& node \"$file\""
}
}
This will kill any running node and restart the file whose tab is open