Javascript 手柄:TypeError:无法读取属性';帮助许可';未定义的
我有一个手柄编译模板的问题。我觉得我完全错过了一些重要的事情,但尽管我可能尝试,我似乎无法解决它,或者在网上找到任何关于为什么会出现这种特殊情况的信息 我正在编译一个使用Gulp手柄的Gulp任务。吞咽任务是:Javascript 手柄:TypeError:无法读取属性';帮助许可';未定义的,javascript,templates,gulp,handlebars.js,precompiled-templates,Javascript,Templates,Gulp,Handlebars.js,Precompiled Templates,我有一个手柄编译模板的问题。我觉得我完全错过了一些重要的事情,但尽管我可能尝试,我似乎无法解决它,或者在网上找到任何关于为什么会出现这种特殊情况的信息 我正在编译一个使用Gulp手柄的Gulp任务。吞咽任务是: gulp.task('build-hbs', function(){ gulp.src('root/app/src/hbs/*.hbs') .pipe(handlebars()) .on('error', notify.onError({ message: 'Erro
gulp.task('build-hbs', function(){
gulp.src('root/app/src/hbs/*.hbs')
.pipe(handlebars())
.on('error', notify.onError({
message: 'Error: <%= error.message %>'
}))
.pipe(declare({
namespace: 'Handlebars.templates',
noRedeclare: true // Avoid duplicate declarations
}))
.pipe(concat('templates.js'))
.pipe(gulp.dest('root/app/js/templates/'));
});
当我运行代码时,我得到一个错误:
TypeError: Cannot read property 'helperMissing' of undefined
这与编译的模板代码有关:
...
var helper, alias1=helpers.helperMissing, alias2="function", alias3=this.escapeExpression;
...
我似乎找不到添加此代码的任何原因,也找不到对把手文档中的helperMissing
函数的任何引用
任何关于为什么会发生这种情况的见解都是非常受欢迎的 最后,问题变成了一个相互冲突的版本 我最终修复它的方法是稍微修改一下吞咽文件:
gulp.task('build-hbs', function(){
gulp.src('root/app/src/hbs/*.hbs')
.pipe(handlebars({
handlebars: require('handlebars')
}))
.pipe(wrap('Handlebars.template(<%= contents %>)'))
.pipe(declare({
namespace: 'Handlebars.templates',
noRedeclare: true // Avoid duplicate declarations
}))
.pipe(insert.prepend('var Handlebars = require("handlebars");\n'))
.pipe(concat('templates.js'))
.pipe(gulp.dest('root/app/js/templates/'));
});
gulp.task('copy', function(){
gulp.src('node_modules/handlebars/dist/handlebars.runtime.js')
.pipe(gulp.dest('root/app/js/libs/'));
});
gravatar
helper缺少的第二个参数导致了一个错误-这只在编译的模板工作时出现,但此时很容易发现
$('#profile').html(Handlebars.templates.profile({
display:'user 1',
hash:'abdcef....'
}));
TypeError: Cannot read property 'helperMissing' of undefined
...
var helper, alias1=helpers.helperMissing, alias2="function", alias3=this.escapeExpression;
...
gulp.task('build-hbs', function(){
gulp.src('root/app/src/hbs/*.hbs')
.pipe(handlebars({
handlebars: require('handlebars')
}))
.pipe(wrap('Handlebars.template(<%= contents %>)'))
.pipe(declare({
namespace: 'Handlebars.templates',
noRedeclare: true // Avoid duplicate declarations
}))
.pipe(insert.prepend('var Handlebars = require("handlebars");\n'))
.pipe(concat('templates.js'))
.pipe(gulp.dest('root/app/js/templates/'));
});
gulp.task('copy', function(){
gulp.src('node_modules/handlebars/dist/handlebars.runtime.js')
.pipe(gulp.dest('root/app/js/libs/'));
});
<div id="nick"><b>{{display}}</b></div>
<div id="image">{{gravatar hash 48}}</div>