当我尝试运行以下 coffeescript 代码时:
request = require('request')
request('http://google.com', (error, response, body) ->
if not error and response.statusCode is 200
console.log(body)
)
我收到以下错误:
request('http://google.com', (error, response, body) ->
^
SyntaxError: Unexpected token >
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
但是当我在 coffeescript.org 的编译器上运行它时,它吐出正确的 javascript。知道发生了什么事吗?
最佳答案
当我在终端上查找 coffeescript 的版本时,它找不到。所以我通过将以下行添加到 bashrc 来导出 coffescript 的路径:
export PATH=/usr/local/share/npm/lib/node_modules/coffee-script/bin/:$PATH
这解决了问题
关于javascript - CoffeeScript + node.js : Unexpected token > (function arrow),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17607895/