Error message is popping up when running js in vscode - javascript

I just started to learn Javascript. I decided the best thing to use was vscode, as I use it for other programming projects. But when I do even a simple statement which I know is right, such as "console.log('hello world')" it gives a error message. Something along the lines of file "c:\Program Files\ Python39\lib\run.py.py" , line 197, in _run_module_as_main. I have tried making a new JavaScript file, and install additional support for js. But It did not work. code:
console.log('hello world')

I think you should start learning by using chrome or firefox console.
Chrome Detail
Firefox Detail

If you want to run JS file on VSCode you can simply go ahead and install node on your machine, and use it run js code in the terminal. Just google it how to install and then use command node <fileName>.js and this will do the job. And in case you don't know how to open terminal in vscode just use command: ctrl + `

Related

vs code terminal externally on when i run javascript code in node js and cannot show output

In my vs code when I write javascript and then I clicked run or write node main.js the vs code terminal externally on the new window cannot show any output.
In visual studio code settings I turned off window conpty setting and visual studio code preference settings but It cannot fix. So, How I can run code internally in vs code terminal.
The "gnode" you seem to be running, is not part of the official distribution of NodeJS. Someone similar with your problem (https://github.com/nodejs/help/issues/3670), found a solution by uninstalling whatever he had installed, and reinstalling the LTS version of node (https://nodejs.org/en/download/).

getting jdk and intellicode errors in vs code. how do i fix it?

I am a very early beginner to coding. I downloaded VS Code so that I could, you know, have somewhere to code in Java. However, I keep getting these two errors telling me these two extensions that I already have installed on VS Code are not working here are the error messages. I already searched through the odds and ends of StackOverflow and have tried everything, and nothing has worked. Any help would be appreciated.
I inputted some code into settings.json under a "java.configuration.runtimes" thing but nothing in it worked. I conformed it to my installation directories and current Java version
Do you have a JDK (Java Development Kit) installed?
If you are on Windows, you can check by clicking on the start button, and search through applications and programs for a Java folder.
If you are on MacOS or Linux, you can open up the terminal/command line and type in "java -version" and if it is properly installed, it will display the version.
If you do not find a JDK installed, install one from https://www.oracle.com/ca-en/java/technologies/downloads/
Download and install the Coding Pack for Java.
It would be helpful to follow this documentation to get started.

JavaScript on Visual Studio Code - is Node required to run a file?

I am currently trying to catch up with some JS basics, before continuing with my node.js-project.
I wanted to execute the file and kept getting the error 'console is not defined', when I wanted to use console.log('Hello!')
The only helpful way to run the file normally was with: node ./myjsfile.js
I installed node.js for that node project.
But for just running super basic JavaScript I don't want node.js.
What are better (lighter!) ways to run my JavaScript files inside Visual Studio Code?
Like what's the most basic way to do it?
No, if you do not currently have Node, you will not have the 'play button' to run the code. So, if you go to Run in the toolbar at the top, you should see some options to run the file.
I'm pretty sure you can just press F1 and then Run Code

Deno not recognised in VS Code's Terminal

I'm sorry, I got this trouble on my VS Code terminal, Deno isn't recognized:
But when I try to do it in my Windows command prompt in the exact same path, it works:
Any idea how to fix that?
I'm not sure how you installed Deno, but I am assuming you did it using Windows Command while your VS Code was running, therefore it have a different terminal session.
If that's the case the VS Code terminal won't find the deno executable because it is a different session and it needs load from the PATH again.
Restart VS Code and see what happens.
If you want to be sure print the PATH variable and confirm that deno is in there.
echo %PATH%
Checkout deno_install for more installation options.
I personally like to use Choco to managed my Windows packages (I thought I run mostly WSL).
choco install deno

Is there an "immediate window" in Visual Studio Code to run Javascript?

Yes, I use F12 in the browser all the time to test out Javascript snippets with the console. I'm tired of that (for the moment anyway).
I've read that in Visual Studio you can use the immediate window to run Javascript interactively.. I've haven't tried it that hard. I think when I did it told me it can't evaluate while in design mode... ugh, what a pain.
I do like to use Visual Studio Code (sublime text historically) sometimes to just mess around with syntax of snippets. Would also be nice if I could just run Javascript there too quickly. Is there a package I could download in VSCode to do so? Or something already built in?
As of (at least) my current version of VS Code (1.5.2), the "Debug Console", while debugging, lets you run arbitrary JavaScript code as you would in the VS Immediate Window. (Similar to as you would for the Chrome Dev Tools Console.)
There is no Immediate Window unlike Visual Studio in VSCode. But you can still execute Javascript in VSCode.
Install the Code Runner Extension - https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner
Open the JavaScript file in VSCode, then use shortcut Ctrl+Alt+N, the code will run and the output will be shown in the Output Window.
I've found this extension that makes a scrathpad for JS, that runs at the same time as you are typing: https://quokkajs.com/
Works on VS Code, Jet Brains, and Atom.
If you don't want to start a debugging session or installing an extension, a simple way to have a JavaScript console is to start Node in a Terminal.
View -> Terminal
Start node (without any argument -you'll need node in your PATH)
Now you have a repl with auto-complete and value preview.
It doesn't have the features of the Chrome Console, but I find it good enough for evaluating JS code while I'm working.
Run the command node in the terminal below the editor, this will create a node environment where arbitrary JavaScript can be entered. You must first have node (and apparently npm) installed from nodejs.
This might do it: https://code.visualstudio.com/Docs/runtimes/nodejs
Node.js is a platform for building fast and scalable server applications using JavaScript. Node.js is the runtime and NPM is the Package Manager for Node.js modules.
To get started, install Node.js for your platform. The Node Package Manager is included in the Node distribution.

Categories