Reputation: 2932
I have reacently started learning coffescript and was trying to fllow a simple tut. However when I try to run my app.coffee file using
coffee app.coffee
command, i keep on getting this 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)
the coffee code is;
###
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")
All my modules are the latest available till date.
Upvotes: 1
Views: 344
Reputation: 9805
Your code is absolutely fine. Coffeescript however reserves keywords like static
therefore if you run coffee -c your_file.coffee
you will see your compiled js in your_file.js
. Open it with editor and see what is wrong.
I am betting that the line app.use express.static(path.join(__dirname, "public"))
gets compiled to somthing like app.use(express["static"](path.join(__dirname,"public"))
. And that causes your error ;)
In future, if there is an error, compile the coffeescript first and then see the compiled version and see what is wrong with it.
Upvotes: 2
Reputation: 17964
I can run the code except for the routes file which you don't provide. I would try to recreate the file and see if there is anything corrupt with the actual file. I have sometimes had problem with Coffeescript files being malformed in indenting and it complains on something else.
The other thing I suspect is that there might be something wrong in your routes file.
Upvotes: 1