节点repl显示错误

node repl showing error

本文关键字:错误 显示 repl 节点      更新时间:2023-09-26

我是node.js的新手,当我尝试运行Hello-world应用程序时,它显示了错误。我创建了一个main.js文件,并使用noderepl调用$node main.js。这导致了错误

SyntaxError: Unexpected identifier
at Object.exports.createScript (vm.js:24:10)
at REPLServer.defaultEval (repl.js:221:25)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.<anonymous> (repl.js:412:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:210:10)
at REPLServer.Interface._line (readline.js:549:8)
at REPLServer.Interface._ttyWrite (readline.js:826:14)

之后,我用正常的命令提示符进行了同样的尝试。我遍历到main.js并执行节点main.js,然后它显示输出。但在示例中,JS是使用noderepl执行的。这完全令人困惑。如果我在repl中尝试$node,它也会显示错误。请帮助

您需要在OS命令/shell提示符下执行node main.js,而不是在node-repl。