我已經開始學習coffescript,並試圖讓一個簡單的嘖嘖。但是,當我嘗試使用 coffee app.coffee
命令運行我的app.coffee文件時,我一直在獲取此異常;無法在nodejs上運行coffeescript應用程序。收到異常
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")
我所有的模塊都是最新的可用日期。
你試過刪除前三行嗎?評論可能只是打破了那裏的解析器。 – arvidkahl 2012-08-12 17:43:26
這是我嘗試的第一件事。我也確保沒有縮進問題。 – 2012-08-12 19:53:27
只需點擊編輯下方的問題並複製源代碼即可試用您的代碼。也許你也嘗試一樣。不要忘記刪除每行開頭的前四個空格。 – vik 2012-08-13 05:51:11