Nunjucks - 找到哪个模板文件导致“模板渲染错误”

时间:2018-04-11 07:54:09

标签: node.js templates nunjucks

我通过Node + Express渲染Nunjucks。

我有很多观点,突然之间我的一个观点就是在下面的堆栈跟踪中抛出错误。

如何找出错误源自哪个模板或辅助/宏?

"Template render error: Template render error: Template render error: Template render error: TypeError: Cannot read property 'height' of null at Object._prettifyError (/code/node_modules/nunjucks/src/lib.js:35:11) at /code/node_modules/nunjucks/src/environment.js:547:19 at eval (eval at _compile (/code/node_modules/nunjucks/src/environment.js:617:18), <anonymous>:151:12) at eval (eval at _compile (/code/node_modules/nunjucks/src/environment.js:617:18), <anonymous>:57:12) at eval (eval at _compile (/code/node_modules/nunjucks/src/environment.js:617:18), <anonymous>:46:11) at /code/node_modules/nunjucks/src/environment.js:555:11 at eval (eval at _compile (/code/node_modules/nunjucks/src/environment.js:617:18), <anonymous>:155:12) at /code/node_modules/nunjucks/src/environment.js:555:11 at eval (eval at _compile (/code/node_modules/nunjucks/src/environment.js:617:18), <anonymous>:105:12) at /code/node_modules/nunjucks/src/environment.js:555:11 at eval (eval at _compile (/code/node_modules/nunjucks/src/environment.js:617:18), <anonymous>:11:11) at /code/node_modules/nunjucks/src/environment.js:597:9 at Template.root [as rootRenderFunc] (eval at _compile (/code/node_modules/nunjucks/src/environment.js:617:18), <anonymous>:188:3) at Template.getExported (/code/node_modules/nunjucks/src/environment.js:595:10) at eval (eval at _compile (/code/node_modules/nunjucks/src/environment.js:617:18), <anonymous>:10:5) at Environment.getTemplate (/code/node_modules/nunjucks/src/environment.js:263:9) at Template.root [as rootRenderFunc] (eval at _compile (/code/node_modules/nunjucks/src/environment.js:617:18), <anonymous>:8:5) at Template.render (/code/node_modules/nunjucks/src/environment.js:540:10) at eval (eval at _compile (/code/node_modules/nunjucks/src/environment.js:617:18), <anonymous>:104:10) at fn (/code/node_modules/a-sync-waterfall/index.js:26:24) at /code/node_modules/a-sync-waterfall/index.js:66:22 at executeSync (/code/node_modules/a-sync-waterfall/index.js:8:15)"

1 个答案:

答案 0 :(得分:1)

正如Aikon Mogwai在评论中所建议的那样,这是关于在node_modules/nunjucks/src/environment.js中添加控制台日志记录的全部内容。

  1. 对于观看者来说,最好在第console.log(err, _Obj3)547this.rootRenderFunc(this.env, context, frame, globalRuntime, function (err, res) {内的捕获内容)

  2. 对于.njk中的错误,最好在console.log(this); 526内的_proto3.render = function render(ctx, parentFrame, cb) {内进行filename

  3. 记录的对象将包含以下有用属性

    • tmplStr - &gt;导致错误的文件的绝对路径
    • export const routing: ModuleWithProviders = RouterModule.forRoot([ { path: '', component: MainComponent, children: [ { path: '', redirectTo: 'notes', pathMatch: 'full'}, { path: 'notes', loadChildren: './notes-page/notes-page.module#NotesPageModule' } ] } ]); - &gt;它可以在错误之前解析的文件的所有内容
    • 一堆上下文对象,包含例如当时存在的所有Nunjucks全局变量和过滤器