obj.hasOwnProperty undefined is not a function nodejs
See original GitHub issueHello,
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:
- Created 8 years ago
- Comments:9 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This could also happen if the object does not have
Object
in it’s prototype chain, for example:The safer way to handle this case would be to change https://github.com/mozilla/nunjucks/blob/master/src/lib.js#L271 to this:
— the only issue with that is that it may break some older browser compatibility, so we’d need to add extra logic for that.
@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 withObject.create(null);
passing them into nunjucks throws this error.