运行Node.js@0.8.15 Express@3.0.4 Jade@0.27.7 Stylus@0.31.0.
由于某种原因得到以下错误.有谁知道这意味着什么?
我不认为我做任何奇怪的事情.当我这样做时会发生这种情况:res.render(view,response);
Property 'visitFunction' of object #<Object> is not a function
at Object.Compiler.visitNode (/app/node_modules/jade/lib/compiler.js:176:32)
at Object.Compiler.visit (/app/node_modules/jade/lib/compiler.js:161:10)
at Object.Compiler.visitBlock (/app/node_modules/jade/lib/compiler.js:253:12)
at Object.Compiler.visitNode (/app/node_modules/jade/lib/compiler.js:176:32)
at Object.Compiler.visit (/app/node_modules/jade/lib/compiler.js:161:10)
at Object.Compiler.compile (/app/node_modules/jade/lib/compiler.js:78:10)
at parse (/app/node_modules/jade/lib/jade.js:101:23)
at Object.exports.compile (/app/node_modules/jade/lib/jade.js:163:9)
at Object.exports.render (/app/node_modules/jade/lib/jade.js:215:17)
at View.exports.renderFile [as engine] (/app/node_modules/jade/lib/jade.js:243:13)
解决方法:
您可能会收到该错误的原因之一是因为您向Object.prototype添加了新属性(通常是方法)
例:
Object.prototype.someNewMethod = function (value1, value2) {
// ... perform some operations
return this;
};
不建议像快速项目的问题#1033中所述那样向Object添加新属性. Object.defineProperty应该与enumerable设置为false一起使用.
使用Object.defineProperty扩展Object的示例
Object.defineProperty(
Object.prototype,
'someNewMethod',
{
writable : false,
// Will not show up in enumerable properties (including for-in loop).
enumerable : false,
configurable : false,
value : function (value1, value2) {
// ... perform some operations
return this;
}
}
);
我有完全相同的问题,使用Object.defineProperty与enumerable:false来定义新属性解决了这个问题.
我希望这会有所帮助.
原文地址:https://codeday.me/bug/20190529/1180477.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。