Reputation: 458
I'm having an issue with gulp-handlebars returning TypeError: Handlebars.template is not a function. It has been working relatively flawless up until now however it appears to have stopped. Any ideas what I'm missing here?
Looking in the bower folder handlebars is showing as 3.0.3 same as with the node modules folder. Looking at the resulting compiled templates file however all templates appear to be showing "compiler":[6,">= 2.0.0-beta.1"] which I suspect maybe the cause
console.log Handlebars in the browser returns handlebars but the template property is an empty object
My package.json
"devDependencies": {
"handlebars": "^3.0.3",
"gulp": "^3.8.11",
"gulp-clean": "^0.3.1",
"gulp-concat": "^2.5.2",
"gulp-declare": "^0.3.0",
"gulp-handlebars": "^4.0.0",
"gulp-jshint": "^1.9.2",
"gulp-rename": "^1.2.0",
"gulp-sequence": "^0.3.2",
"gulp-uglify": "^1.1.0",
"gulp-watch": "^4.1.1",
"gulp-wrap": "^0.11.0",
"gulp-yuidoc": "^0.1.2"
}
My bower.json
"dependencies": {
"bootstrap": "~3.3.2",
"jquery": "~2.1.3",
"sammy": "~0.7.6",
"showdown": "~0.4.0",
"handlebars": "3.0.3",
"pagedown": "~1.1.0"
},
"devDependencies": {
"jqueryui": "~1.11.4"
}
My gulp tasks
gulp.task('templates', function() {
gulp.src(['public/templates/**/*.hbs', 'public/templates/*.hbs'])
.pipe(handlebars({
handlebars: require('handlebars')
}))
.pipe(wrap('Handlebars.template(<%= contents %>)'))
.pipe(declare({
namespace: 'Handlebars.templates',
noRedeclare: true, // Avoid duplicate declarations
}))
.pipe(concat('templates.js'))
.pipe(gulp.dest('public/js/'));
});
gulp.task('watch', function() {
gulp.watch(['public/templates/*.hbs', 'public/templates/**/*.hbs'], ['templates']);
gulp.watch(['public/js/*.js', 'public/js/**/*.js'], ['build']);
});
Link to Github Issue - https://github.com/lazd/gulp-handlebars/issues/55
Thanks
Upvotes: 0
Views: 2491
Reputation: 458
When concatenating and minifying through gulp make sure your paths are correct. Mine changed and gulp didn't throw any errors about not finding the files!
Upvotes: 0