我在这里关注 Steven Sanderson 的视频以开始使用 NodeJS。我已经安装EJS
和ejs-middleware
模块。server.js 如下所示:
var express=require('express'),
app = express(),
ejsMiddleware = require('ejs-middleware');
app.use(ejsMiddleware(__dirname + '/static', 'html', app));
但它会抛出异常,例如:
app.use(ejsMiddleware(__dirname + '/static', 'html', app));
例外是:
Application has thrown an uncaught exception and is terminated:
TypeError: Object function app(req, res){ app.handle(req, res); } has no method 'register'
at C:\Users\...Inventify\node_modules\ejs-middleware\ejs-middleware.js:9:23
at Object.<anonymous> (C:\Users\...Inventify\server.js:8:9)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
at Function._load (module.js:311:12)
at Module.require (module.js:359:17)
at require (module.js:375:17)
at Object.<anonymous> (C:\Program Files (x86)\iisnode-dev\release\x86\interceptor.js:211:1)
at Module._compile (module.js:446:26)
我无法得到它的任何头部或尾部。请帮我。
编辑:-根据@Peter Lyons的这个答案进行了以下更改:
老的
registerInApp.register('.' + extension, ejs);
新的
registerInApp.engine('.' + extension, require(ejs));
但现在得到以下异常:
TypeError: Object #<Object> has no method 'substring'
at Function._resolveLookupPaths (module.js:235:23)
at Function._resolveFilename (module.js:327:31)
at Function._load (module.js:279:25)
at Module.require (module.js:359:17)
at require (module.js:375:17)
at C:\Users\...Inventify\node_modules\ejs-middleware\ejs-middleware.js:10:47
at Object.<anonymous> (C:\Users\...Inventify\server.js:12:9)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)