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

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

Closed
lewiswalsh opened this issue Apr 20, 2015 · 7 comments
Closed

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

lewiswalsh opened this issue Apr 20, 2015 · 7 comments

Comments

@lewiswalsh
Copy link

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
Copy link

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
Copy link
Author

That solved it for me too! Thanks.

@ericf
Copy link
Owner

ericf commented Apr 20, 2015

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
Copy link

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

@ee99ee
Copy link

ee99ee commented Apr 21, 2015

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
Copy link

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 added a commit that referenced this issue Apr 23, 2015
Handlebars went through an ES6 conversation refactor that was
released as a patch. There was a semantic change to
`Handlebars.compileTemplate()` that caused Express Handlebars to
break.

The Handlebars maintainer was unwilling to fix the issue in
Handlebars which pushed the problem upstream. In order to prevent any
further upstream breakage, I'm addressing it here by replacing `null`
with `undefined` for default values that are passed to Handlebars.

See: handlebars-lang/handlebars.js#1003
Related discussion: handlebars-lang/handlebars.js@4bed826#commitcomment-10807064

Fixes: #125 #128
@ericf
Copy link
Owner

ericf commented Apr 23, 2015

Release a guard against this in 2.0.1

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

No branches or pull requests

6 participants