简体   繁体   English

“node filename.js”在 vs 代码中不起作用

[英]“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:我在包含console.log的 vs 代码中创建了一个 hello.js 文件,当我输入终端node hello.js时,出现以下错误:

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:我的js文件内容:

console.log("hello");

Is it because vs code?是因为vs代码吗? Should I use another IDE?我应该使用另一个 IDE 吗?

UPDATE: The problem also persists with Node.js Command Prompt更新: Node.js 命令提示符也存在问题
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 UPDATE2:我用 Sublime Text 而不是 VS Code 再次创建了同一个文件,它可以工作..这可能是 VS Code 的一个错误

Where's your hello.js file code?你的 hello.js 文件代码在哪里? Did you have the proper code?你有正确的代码吗?

Example:例子:

hello.js file (make sure you save the file): hello.js 文件(确保保存文件):

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.在 vs 代码(Visual Studio 代码)中打开终端,或热键按 ctrl + `(此 ` 键在键盘上的数字 1 旁边),或 go 到顶部菜单视图 > 终端。

Type node hello键入节点你好

It will output: Hello它将 output: 你好

命令提示符

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.您的代码很完美,运行良好,我认为您的节点安装不正确,您可以检查它是否运行另一个像这样的 js 文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Docker容器中运行命令&#39;node filename.js&#39; - Run command 'node filename.js' inside a Docker container 如何在Electron中触发节点filename.js文件? - How to trigger node filename.js file in Electron? 运行节点fileName.js命令后如何返回终端执行? - How to return to terminal execution after running node fileName.js command? 当我输入终端命令“$ node fileName.js”时,concole 会抛出“SyntaxError: Unexpected token &#39;&lt;&#39;”错误 - When I enter the terminal command "$ node fileName.js" the concole throws out a "SyntaxError: Unexpected token '<'" error jscs 错误:validateLineBreaks:filename.js 处的换行符无效 - jscs error : validateLineBreaks: Invalid line break at filename.js js 文件应该有什么名称,带有奇怪结尾的 url 引导:“.../filename.js?crc=6»? - What names should js files have, to which urls with a strange ending lead: ".../filename.js?crc=6»? ver = 3.1.2是什么意思?在ajax.js或filename.js末尾的ver = 3.1.2是什么意思? - What does ver=3.1.2 at the end of ajax.js or filename.js?ver=3.1.2 mean? vs代码节点js中没有intellisense - There is no intellisense in vs code node js Node.js v18.3.0“导出”和“导入”VS 代码不起作用 - Node.js v18.3.0 "Export" and "Import" VS Code not working VS Code Node.js macOS 调试不起作用 - 我什至不知道如何说明问题 - VS Code Node.js macOS debugging not working - I don't even know how to state the problem
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM