Express.js 中的 EJS - Express Helpers 不工作 - (app) 在 require 中
我正在将 EJS 模板引擎与express.js 一起使用,并且我想使用视图助手。我在 github 上找到了这个: https://github.com/tanema/express-helpers,但是当我尝试使用它时,我收到此错误:
TypeError: object is not a function
at Object.CALL_NON_FUNCTION (native)
at Object. (/home/node/app/app.js:12:40)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
at Function._load (module.js:293:12)
at Array. (module.js:421:10)
at EventEmitter._tickCallback (node.js:126:26)
而这一行是 app.js 上的第 12 行:
var helpers = require('express-helpers')(app);
如果我这样做,
var helpers = require('express-helpers');
它确实会抛出错误,但也不起作用。
我的 app.js 文件顶部如下:
var express = require('express');
var app = express.createServer();
app.listen(34573);
// !Requires
var helpers = require('express-helpers')(app);
有想法吗?
提前致谢!
I'm using the EJS template engine with express.js and I want to use the view helpers. I found this on github: https://github.com/tanema/express-helpers, but when I try to use it I get this error:
TypeError: object is not a function
at Object.CALL_NON_FUNCTION (native)
at Object. (/home/node/app/app.js:12:40)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
at Function._load (module.js:293:12)
at Array. (module.js:421:10)
at EventEmitter._tickCallback (node.js:126:26)
whereas this line is line 12 on app.js:
var helpers = require('express-helpers')(app);
and if I make it
var helpers = require('express-helpers');
it does throw the error, but also does not work.
My top of the app.js file is as follows:
var express = require('express');
var app = express.createServer();
app.listen(34573);
// !Requires
var helpers = require('express-helpers')(app);
Ideas?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
评论(4)
彩扇题诗2024-12-07 14:06:21
你也可以使用这个 npm 包,它提供了更好的&扩展的帮助者。
https://www.npmjs.com/package/native-view-helpers
npm install native-view-helpers --save
希望它能帮助别人。
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我的不好。
事实证明,我的链接是混合的,而我尝试的用法是针对分叉分支的。我克隆了分支,并覆盖了默认的 https://github.com/masahiroh/express-helpers 并且代码按照正确的分支正常工作。
无论如何,谢谢!
My bad.
It turns out that I had my links mixed, and the usage I was trying was meant for a forked branch. I cloned the branch, and overwrote the default https://github.com/masahiroh/express-helpers and the code worked as it was supposed to with the correct branch.
Thanks anyway!