Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Express Basics (2015) Using Templates with Express Scaffolding Your Project’s Templates

Alex Flores
Alex Flores
7,864 Points

Jade template engine - issues with indenting??

The learning curve on this one is steep indeed. I keep having issues with indenting? As soon as I fix one thing, another indent problem arises. Then it says "Cannot read property 'description' of undefined"

What is going on with Jade?

2 Answers

Justin Coen
seal-mask
.a{fill-rule:evenodd;}techdegree
Justin Coen
Full Stack JavaScript Techdegree Student 12,829 Points

Jade is picky when it comes to tabs or spacing for indentation. If you mix the two, that is tabs with spaces, in your jade code then you'll get an indentation error.

If you're using sublime text, on the bottom right corner you'll see the 'tab size' button. If you click on that button you'll see the options to either convert indentation to tabs or spaces. Simply select your jade code and select one of those two and that should fix your indentation errors, it always has in my experience at least.

Furthermore, if you highlight your code you can tell whether you have an indentation of a space or a tab. An indentation of a space will show a dot to the left of your indentation, and an indentation of a tab will show a straight line.

As for the other error, "Cannot read property 'description' of undefined" I'm not entirely sure, you'll have to post your code.

Thanks for the heads up. I downloaded the files from Treehouse for this video (b/c I wanted the Bootstrap code included in the revised video example). After I manipulated the files to move the duplicated header/menu content into the layout.jade file I had combinations of spaces/tabs all over the place. After switching all white space to tabs the Jade "indent" errors are gone, but I wouldn't have had any idea where to begin without your post. Thanks again!

"Cannot read property 'description' of undefined" happens when your trying to access the property of the object that is not defined

var x = undefined
x.y "Cannot read property 'description' of undefined"
var x = {}
x.y // Will not throw undefined error
//To fix use
var x= post || {}