简体   繁体   中英

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:

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? If so, the reason for the error is simple. It's because:

/Users/francescocolonnese/Desktop/appunti.js

is not valid javascript code. 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.

Inside the node shell you should only type valid 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 -p /Users/francescocolonnese/Desktop/appunti.js

"@infomaniac - I would try deleting this whole folder: /usr/local/share/systemtap/"

worked for me, thanks!

Uninstall node.js

brew uninstall node

brew uninstall node --force

Output from 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.

Remove /usr/local/share/systemtap/

$ sudo rm -rf /usr/local/share/systemtap/

Reinstall node.js

brew install node

Fix unlinked kegs

$ brew link node

Output:

Linking /usr/local/Cellar/node/0.12.4... 6 symlinks created

nodejs.org卸载您安装的节点版本,然后运行:

brew update

brew uninstall node --force

brew install node

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