Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'filename' of undefined #403

Closed
Fuitad opened this issue Nov 13, 2011 · 25 comments
Closed

Cannot read property 'filename' of undefined #403

Fuitad opened this issue Nov 13, 2011 · 25 comments

Comments

@Fuitad
Copy link

Fuitad commented Nov 13, 2011

I've upgraded jade from 0.14.2 to 0.17.0 and I can't run my app anymore.

I tried stripping my app to empty views and controllers and no dice.

Do you have any idea what changed between those two versions that would cause this?

at anonymous (eval at (/Volumes/Fuitad/Documents/www/node_modules/jade/lib/jade.js:161:8))
at Object. (/Volumes/Fuitad/Documents/www/node_modules/jade/lib/jade.js:166:12)
at ServerResponse._render (/Volumes/Fuitad/Documents/www/node_modules/express/lib/view.js:422:21)
at ServerResponse.render (/Volumes/Fuitad/Documents/www/node_modules/express/lib/view.js:315:17)
at /Volumes/Fuitad/Documents/www/app.js:187:7
at callbacks (/Volumes/Fuitad/Documents/www/node_modules/express/lib/router/index.js:272:11)
at param (/Volumes/Fuitad/Documents/www/node_modules/express/lib/router/index.js:246:11)
at pass (/Volumes/Fuitad/Documents/www/node_modules/express/lib/router/index.js:253:5)
at Router._dispatch (/Volumes/Fuitad/Documents/www/node_modules/express/lib/router/index.js:280:4)
at Object.handle (/Volumes/Fuitad/Documents/www/node_modules/express/lib/router/index.js:45:10)

@tj
Copy link
Contributor

tj commented Nov 14, 2011

recent jades have include / extend so they need the current view filename so they can do relative lookups. Which version of express are you using? console.log(express.version), more recent versions should have fixed this bug as express 2.x should be passing the filename to the engine

@Fuitad
Copy link
Author

Fuitad commented Nov 15, 2011

2.5.0

@Fuitad
Copy link
Author

Fuitad commented Nov 15, 2011

Weird thing is that I get this:

TypeError: /Volumes/Fuitad/Documents/www/views/http_error.jade:1
  > 1| doctype 5
    2| html
    3|   head
    4|     title #{(typeof(title) != 'undefined' ? title + ' - ' : '')} Welcome

Cannot read property 'filename' of undefined

So it gets into my first template just fine. :\

UPDATE:

I commented out my error handler and got this message instead:

TypeError: /Volumes/Fuitad/Documents/www/views/index.jade:1
  > 1| extends ./layout/layout-index
    2| 
    3| block content
    4|   div(class='grid_14 prefix_1 suffix_1')

Cannot read property 'filename' of undefined

@tj
Copy link
Contributor

tj commented Nov 15, 2011

hmm express should be setting that for you, could you post part of that route and the package.json deps? are you using kue?

@Fuitad
Copy link
Author

Fuitad commented Nov 15, 2011

I'm not using kue. (should I be?)

app.js (I stripped it down as much as I could and still not working)

var conf          = require('./conf'),
express       = require('express'),
port          = parseInt(process.env.PORT,10) || 3000,
replPort      = parseInt(process.env.REPLPORT,10) || 8888,
ip            = process.env.IP || null;

var pub = __dirname + '/public';

var app = express.createServer();
app.use(app.router);
app.use(express.static(pub));
//app.use(express.errorHandler({ dump: true, stack: true }));

app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
//app.set('view options', { layout: false });  //<- tried this with and without, no change

app.get('/', function(req, res){
  res.render('index');
});

app.listen(port, ip, function(){
  console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
});

package.json

{
    "name": "www",
    "version": "0.0.2",
    "private": true,
    "dependencies": {
        "express"           : ">=2.4.4",
        "jade"              : ">=0.14.2",
        "async"             : ">=0.1.9",
        "mongoskin"         : ">=0.1.3",
        "i18n"              : ">=0.3.0",
        "request"           : ">=2.0.2",
        "everyauth"         : ">=0.2.18",
        "connect-mongo"     : ">=0.1.5",
        "node-markdown"     : ">=0.1.0",
        "cluster"           : ">=0.6.9",
        "gsl"               : ">=0.0.6",
        "redis"             : ">=0.6.7",
        "zlibstream"        : ">=1.0.0",
        "memcached"         : ">=0.0.1"
    }
}

@tj
Copy link
Contributor

tj commented Nov 15, 2011

hmm that jade is pretty old (we're on 0.17.0 now) maybe updating to a more recent one will help

@Fuitad
Copy link
Author

Fuitad commented Nov 15, 2011

As stated in my first message, I'm on 0.17.0 now. :-/

 $ cat node_modules/jade/package.json  | grep version
  "version": "0.17.0",

@tj
Copy link
Contributor

tj commented Nov 15, 2011

sorry all I saw was >=0.14.2, at a glance I thought you had it pegged at that version. This seems very weird.. all I can suggest is maybe stepping through to the res.render() call, it should be setting filename for you in express

@Fuitad
Copy link
Author

Fuitad commented Nov 15, 2011

I reverted to my previous version and started testing each jade version since 0.14.2.

Version 0.15.4 works perfectly well and the "Cannot read property 'filename' of undefined" problem starts happening with version 0.16.0.

Do you remember any changes between those two versions that could explain my problem?

@tj
Copy link
Contributor

tj commented Nov 15, 2011

unless you're using the newer include <path> or inheritance features Jade shouldn't even be using that, a quick step through with the debugger should show the problem though just place debugger before the render call and do $ node debug myapphere

@Fuitad
Copy link
Author

Fuitad commented Nov 15, 2011

Does this help at all?

  res.render('index', {
      ^
debug> step
break in #<ServerResponse>.render(view=index, opts=#<Object>, fn=undefined, parent=undefined, sub=undefined), /Volumes/Fuitad/Documents/www/node_modules/express/lib/view.js:310
  if ('function' == typeof opts) {
  ^
debug> print opts
{ layout: 'layout/layout-index.jade' }

@tj
Copy link
Contributor

tj commented Nov 15, 2011

express would be adding it lower than that, if you do step and then just press enter a bunch (it'll repeat the prev command) until an error occurs and paste that then I can see what's going on

@Fuitad
Copy link
Author

Fuitad commented Nov 15, 2011

@Fuitad
Copy link
Author

Fuitad commented Nov 16, 2011

I've nailed it down to this:

app.locals({
  __              : i18n.__,
  __n             : i18n.__n
});

I'm not too sure why it would have an effect on jade but it does. These functions are use all over the place in my templates to allow translations. Example:

h2(id='index_localization') #{__('Welcome to our site')} 

Do you have any idea why it wouldn't work anymore?

@tj
Copy link
Contributor

tj commented Nov 16, 2011

ohhhhh that makes sense, jade uses a var called __ to store line numbers etc for error reporting

@Fuitad
Copy link
Author

Fuitad commented Nov 16, 2011

Changed __ to __i and it's working now. Bah!

Thanks a ton for your support and especially, your patience :).

@Fuitad Fuitad closed this as completed Nov 24, 2011
@cleishm
Copy link
Contributor

cleishm commented Dec 23, 2011

I just ran into exactly the same problem. Given that i18n is going to be pretty common, would it make sense to use a different internal var in jade for this? maybe __lineno?

@tj
Copy link
Contributor

tj commented Dec 23, 2011

why not just use _ instead of __, that was why I changed it originally

@cleishm
Copy link
Contributor

cleishm commented Dec 23, 2011

Because that's also very commonly used globally for the excellent underscore.js:

http://documentcloud.github.com/underscore/

@cleishm
Copy link
Contributor

cleishm commented Dec 23, 2011

I submitted pull #449, and chose __jade (since you might want to add more things than just line number and filename in future).

@tj
Copy link
Contributor

tj commented Dec 23, 2011

haha yeah im aware of underscore but I didn't think about that since I dont use it. I guess we could change it

@cleishm
Copy link
Contributor

cleishm commented Dec 23, 2011

Yeah. Since you allow adding user named vars into that scope, probably best to avoid anything that isn't clearly an internal name. Hence __jade.

@tj
Copy link
Contributor

tj commented Dec 23, 2011

yup

@enyo
Copy link

enyo commented Jan 16, 2013

@visionmedia That's done now, right? __ is free to use?

@ForbesLindesay
Copy link
Member

Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants