简体   繁体   中英

“node filename.js” is not working in vs code

I created a hello.js file in vs code containing a console.log , and when I type in the terminal node hello.js I get the following error:

SyntaxError: Invalid or unexpected token
    at Module._compile (internal/modules/cjs/loader.js:721:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

The content of my js file:

console.log("hello");

Is it because vs code? Should I use another IDE?

UPDATE: The problem also persists with Node.js Command Prompt
UPDATE2: I created the same file again with Sublime Text instead of VS Code and it works.. it was probably a bug from VS Code

Where's your hello.js file code? Did you have the proper code?

Example:

hello.js file (make sure you save the file):

console.log('Hello')

Open terminal in vs code (visual studio code), or hotkey press ctrl + ` (this ` key is next to number 1 on your keyboard), or go to top menu View > Terminal.

Type node hello

It will output: Hello

命令提示符

Your code is perfect it's run fine, I think your node in not install properly you cna check it run another js file like this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM