TypeError: Handlebars.template is not a function Handlebars 3.0.3

TypeError: Handlebars.template is not a function Handlebars 3.0.3

我遇到了 gulp-handlebars 返回 TypeError 的问题:Handlebars.template 不是一个函数。到目前为止,它一直在相对完美地工作,但它似乎已经停止了。知道我在这里遗漏了什么吗?

查看 bower 文件夹 handlebars 显示为 3.0.3 与节点模块文件夹相同。查看生成的编译模板文件,但所有模板似乎都显示 "compiler":[6,">= 2.0.0-beta.1"] 我怀疑这可能是原因

console.log 浏览器中的把手 returns 把手但是模板 属性 是一个空对象

我的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"
  }

我的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"
  }

我的 gulp 任务

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 至 Github 问题 - https://github.com/lazd/gulp-handlebars/issues/55

谢谢

通过 gulp 连接和缩小时,请确保您的路径正确。我的更改了,gulp 没有抛出任何关于找不到文件的错误!