question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

obj.hasOwnProperty undefined is not a function nodejs

See original GitHub issue

Hello,

I was noticing some discrepancies in some of the rendering of the nunjuck templates. After enough digging around I boiled it down to different nodejs versions between development and production. However the production machine has a more resent version of nodejs.

~ > node --version
v0.12.2

With version v0.12.x of node, this line

https://github.com/mozilla/nunjucks/blob/master/src/lib.js#L271

fails with TypeError: undefined is not a function.

Has anyone encountered this, is there any know workaround?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
devoidfurycommented, Jun 24, 2015

This could also happen if the object does not have Object in it’s prototype chain, for example:

extra = Object.create(null)

The safer way to handle this case would be to change https://github.com/mozilla/nunjucks/blob/master/src/lib.js#L271 to this:

 if(Object.prototype.hasOwnProperty.call(obj, k)) {

— the only issue with that is that it may break some older browser compatibility, so we’d need to add extra logic for that.

0reactions
asprousecommented, Dec 1, 2016

@carljm This is enough of a problem that ESLint has a rule about it. http://eslint.org/docs/rules/no-prototype-builtins This setting was enabled in v4 of Airbnb’s widely (43k+ stars) used ESLint config. I have noticed some libraries, notably graphql-js, creating objects with Object.create(null);passing them into nunjucks throws this error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

hasOwnProperty is not a function in Node.js? - Stack Overflow
A way around the error is to call hasOwnProperty on Object explicitly, and bind it to the object, like so: // Calls "hasOwnProperty"...
Read more >
Object.prototype.hasOwnProperty() - JavaScript | MDN
The hasOwnProperty() method returns true if the specified property is a direct property of the object — even if the value is null...
Read more >
hasOwnProperty is not a function in Node.js?
1) Solution. Most objects in javascript inherit from Object; it's possible to intentionally create objects that inherit from nothing (i.e., null ), and ......
Read more >
Javascript hasownproperty method - Flexiple
This method is used to check whether the property on an object belongs to the mentioned object or not. If the property belongs...
Read more >
TypeError req body hasOwnProperty is not a function
obj.hasOwnProperty undefined is not a function nodejs #468. obj.hasOwnProperty undefined is not a function nodejs #468. fotisp undefined is not a function.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found