ericf / express-handlebars

A Handlebars view engine for Express which doesn't suck.
BSD 3-Clause "New" or "Revised" License
2.31k stars 384 forks source link

TypeError: Cannot use 'in' operator to search for 'data' in null #125

Closed lewiswalsh closed 9 years ago

lewiswalsh commented 9 years ago

Getting a bizarre error I've not seen before. The only change I made was the way Git handles line endings, but I doubt that would cause it. Using Express-handlebars v2.0.0 when I try to "res.render" I get the following:

TypeError: Cannot use 'in' operator to search for 'data' in null 
    at Object.compile (.\node_modules\express-handlebars\node_modules\handlebars\dist\cjs\handlebars\compiler\compiler.js:467:19)
    at HandlebarsEnvironment.hb.compile (.\node_modules\express-handlebars\node_modules\handlebars\dist\cjs\handlebars.js:34:41)
    at ExpressHandlebars._compileTemplate (.\node_modules\express-handlebars\lib\express-handlebars.js:239:28)
    at ExpressHandlebars.<anonymous> (.\node_modules\express-handlebars\lib\express-handlebars.js:124:25)

The issue seems to be because line 124 is: return this._compileTemplate(file, this.compilerOptions);

But compilerOptions is set to null here on line 31: compilerOptions: null,

Any help would be greatly appreciated.

marufsiddiqui commented 9 years ago

I was also facing this issue. Downgrading to 1.2.2 solved the problem for me.

My findings were that express-handlebars has dependency to handlebars like "handlebars": "^3.0.0", so it tries to install the latest handlebars. Current handlebars version is 3.0.2 somehow breaks express-handlebars

lewiswalsh commented 9 years ago

That solved it for me too! Thanks.

ericf commented 9 years ago

I will look into the Handlebars' changelog to see what changed between 3.0.0 and 3.0.2. From what you're saying, it looks like semver was broken, which is unfortunate. Another way around this issue would be you add "handlebars": "3.0.0" to your package.json and pass that copy of Handlebars to Express Handlebars via the config options.

msamblanet commented 9 years ago

handlebars.js Issue 1003 was opened on that project and has a suggested workaround while this gets worked out.

ee99ee commented 9 years ago

Sweet mother of Jesus, I have spent hours troubleshooting this issue... I thought I was going mad. Indeed, adding the workaround mentioned in handlebars.js Issue 1003 worked for me as well. What a pain!

coreycauble commented 9 years ago

It looks like it is happening because of handlebars 3.0.2 which was being installed bundled with your package. I killed my node-modules and force loaded handlebars 3.0.1 ( npm install --save handlebars@3.0.1 ) then did a npm install and this seems to have resolved my problem. I spent a lot of time troubleshooting because it was only happening on my production box. What a pain. For some reason this page hasn't been indexed by google so it never showed up in a search. It would have saved me some headache. Bah! Just thought I would share a quick and easy fix that doesn't require mods to sources.

ericf commented 9 years ago

Release a guard against this in 2.0.1