Template was precompiled with an older version of Handlebars than the current runtime

大憨熊 提交于 2019-12-04 06:27:37

There is a better way to compile a template using a specific version of handlebars which is covered in the README: https://github.com/lazd/gulp-handlebars#compiling-using-a-specific-handlebars-version

Make sure you've specified the handlebars version in your app's package.json file:

{
  "devDependencies": {
    "handlebars": "^4.0.5"
  }
}

Then require handlebars by passing it as a gulp-handlebars option in your gulpfile:

gulp.task('templates', function () {
  gulp.src('templates/*.hbs')
    .pipe(handlebars({
      handlebars: require('handlebars')
    }))
    .pipe(wrap('Handlebars.template(<%= contents %>)'))
    .pipe(declare({
      namespace: 'MyApp.templates',
      noRedeclare: true, // Avoid duplicate declarations
    }))
    .pipe(concat('templates.js'))
    .pipe(gulp.dest('js/dist'));
});

Ok, my problem was in the gulp-handlebars package, because in the package loader, it is loading a minor version.

I update it manually and I solved my problem. Go to node_modules folder, find gulp-handlebars folder, open package.json, and update the dependicies like this:

"dependencies": {
    "gulp-util": "^3.0.4",
    "handlebars": "4.0.5",
    "through2": "^0.6.3"
  }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!