[英]Node.js can't compile my .js files (OSX Yosemite)
I'm running node.js on my macbook pro and i really can't understand why everytime i try to compile something by my terminal i get this error: 我在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)
can someone help me through this..? 有人可以帮我解决这个问题吗?
Wait, are you trying to run a js file by typing it's name in the node interactive shell? 等待,您是否正在尝试通过在节点交互式外壳程序中键入其名称来运行js文件? If so, the reason for the error is simple.
如果是这样,则错误原因很简单。 It's because:
这是因为:
/Users/francescocolonnese/Desktop/appunti.js
is not valid javascript code. 是无效的JavaScript代码。 Indeed, looking at the error you can see that node tries to interpret
//
as a regular expression as: 确实,查看错误后,您可以看到该节点尝试将
//
解释为正则表达式为:
/Users/francescocolonnese
and complains that francescocolonnese
is not a valid regex switch. 并抱怨
francescocolonnese
不是有效的正则表达式开关。
Inside the node shell you should only type valid javascript. 在节点外壳中,您应该只输入有效的javascript。 If you insist on doing this you can type this:
如果您坚持要执行此操作,则可以输入以下内容:
require('/Users/francescocolonnese/Desktop/appunti.js')
But that's the wrong way to do it. 但这是错误的方法。 Instead simply ask node.js to run that file:
而是简单地要求node.js运行该文件:
node -p /Users/francescocolonnese/Desktop/appunti.js
"@infomaniac - I would try deleting this whole folder: /usr/local/share/systemtap/" “ @infomaniac-我将尝试删除整个文件夹:/ usr / local / share / systemtap /”
worked for me, thanks! 为我工作,谢谢!
Uninstall node.js 卸载node.js
brew uninstall node
brew uninstall node --force
Output from brew doctor
: brew doctor
输出:
Linking /usr/local/Cellar/node/0.12.4... Error: Could not symlink share/systemtap/tapset/node.stp /usr/local/share/systemtap/tapset is not writable. 链接/usr/local/Cellar/node/0.12.4 ...错误:无法符号链接share / systemtap / tapset / node.stp / usr / local / share / systemtap / tapset是不可写的。
Remove /usr/local/share/systemtap/ 删除/ usr / local / share / systemtap /
$ sudo rm -rf /usr/local/share/systemtap/
Reinstall node.js 重新安装node.js
brew install node
Fix unlinked kegs 修复未链接的小桶
$ brew link node
Output: 输出:
Linking /usr/local/Cellar/node/0.12.4... 6 symlinks created 链接/usr/local/Cellar/node/0.12.4 ...已创建6个符号链接
从nodejs.org
卸载您安装的节点版本,然后运行:
brew update
brew uninstall node --force
brew install node
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.