无法在nodejs上运行coffeescript应用程序。 接收exception

我已经开始学习coffescript,并尝试着简单的啧啧。 但是,当我尝试使用coffee app.coffee命令运行我的app.coffee文件时,我一直得到这个exception;

 PS C:\Users\Office\Workspace\node\blog-demo\coffeepress> coffee .\app.coffee Error: In .\app.coffee, Parse error on line 1: Unexpected ' ' at Object.parseError (C:\Users\Rishav\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\parser.js:477 :11) at Object.parse (C:\Users\Rishav\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\parser.js:554:22) at exports.compile.compile (C:\Users\Rishav\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\coffee- script.js:43:20) at Object.exports.run (C:\Users\Rishav\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\coffee-scrip t.js:79:34) at compileScript (C:\Users\Rishav\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\command.js:175:29 ) at fs.stat.notSources.(anonymous function) (C:\Users\Rishav\AppData\Roaming\npm\node_modules\coffee-script\lib\coffe e-script\command.js:150:18) at fs.readFile (fs.js:176:14) at Object.oncomplete (fs.js:297:15) 

咖啡代码是;

 ### Module dependencies. ### express = require("express") routes = require("./routes") http = require("http") path = require("path") app = express() app.configure -> app.set "port", process.env.PORT or 3000 app.set "views", __dirname + "/views" app.set "view engine", "jade" app.use express.favicon() app.use express.logger("dev") app.use express.bodyParser() app.use express.methodOverride() app.use app.router app.use express.static(path.join(__dirname, "public")) app.configure "development", -> app.use express.errorHandler() app.get "/", routes.index http.createServer(app).listen app.get("port"), -> console.log "Express server listening on port " + app.get("port") 

我所有的模块都是最新的可用date。

你的代码是绝对好的。 然而,Coffeescript保留关键字像static因此,如果您运行coffee -c your_file.coffee您将在your_file.js中看到您编译的js。 用编辑器打开它,看看有什么不对。

我打赌,行app.use express.static(path.join(__dirname, "public"))被编译为像app.use(express["static"](path.join(__dirname,"public")) 。那会导致你的错误;)

将来,如果出现错误,请先编译咖啡标记,然后查看编译后的版本,看看有什么问题。

我可以运行除了你不提供的路线文件之外的代码。 我会尝试重新创build该文件,看看是否有任何损坏的实际文件。 我有时遇到了Coffeescript文件在缩进时格式不正确的问题,并且抱怨别的东西。

另一件我怀疑是在你的路线文件中可能有错误。