我在Macbook Pro上运行node.js,我真的不明白为什么每次我尝试通过终端进行编译时都会出现此错误:
MBPdiFrancesco:~ francescocolonnese$ node -p
> /Users/francescocolonnese/Desktop/appunti.js
SyntaxError: Invalid flags supplied to RegExp constructor 'francescocolonnese'
at new RegExp (native)
at repl:1:1
at REPLServer.defaultEval (repl.js:132:27)
at bound (domain.js:254:14)
at REPLServer.runBound [as eval] (domain.js:267:12)
at REPLServer.<anonymous> (repl.js:279:12)
at REPLServer.emit (events.js:107:17)
at REPLServer.Interface._onLine (readline.js:214:10)
at REPLServer.Interface._line (readline.js:553:8)
at REPLServer.Interface._ttyWrite (readline.js:830:14)
有人可以帮我解决这个问题吗?
等待,您是否正在尝试通过在节点交互式外壳程序中键入其名称来运行js文件?如果是这样,则错误原因很简单。这是因为:
/Users/francescocolonnese/Desktop/appunti.js
是无效的javascript代码。确实,查看错误后,您可以看到该节点尝试将//
正则表达式解释为:
/Users/francescocolonnese
并抱怨说这francescocolonnese
不是有效的正则表达式开关。
在节点外壳中,您应该只输入有效的javascript。如果您坚持要执行此操作,则可以输入以下内容:
require('/Users/francescocolonnese/Desktop/appunti.js')
但这是错误的方法。而是简单地要求node.js运行该文件:
node -p /Users/francescocolonnese/Desktop/appunti.js
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句