Gulp 模板是使用比当前运行时更旧版本的Handlebar预编译的

Gulp 模板是使用比当前运行时更旧版本的Handlebar预编译的,gulp,handlebars.js,Gulp,Handlebars.js,我有这个错误,但和我的问题不同的是我用的是咕噜而不是咕噜 首先,我的handlebar运行时是handlebar v4.0.5(js文件) 手柄-v的输出为4.0.5 这是我的gulpfile.js: var gulp = require('gulp'); var uglify = require('gulp-uglify'); var handlebars = require('gulp-handlebars'); var wrap = require('gulp-wrap'); var de

我有这个错误,但和我的问题不同的是我用的是咕噜而不是咕噜

首先,我的handlebar运行时是handlebar v4.0.5(js文件)

手柄-v的输出为4.0.5

这是我的gulpfile.js

var gulp = require('gulp');
var uglify = require('gulp-uglify');
var handlebars = require('gulp-handlebars');
var wrap = require('gulp-wrap');
var declare = require('gulp-declare');
var concat = require('gulp-concat');

gulp.task('default', ['templates','scripts'], function () {

});

gulp.task('templates', function () {
    gulp.src('templates/*.hbs')
      .pipe(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'));
});

gulp.task('scripts', function () {
    return gulp.src([
     'bower_components/handlebars/handlebars.runtime.js',
     'bower_components/jquery/dist/jquery.js',
     'bower_components/bootstrap/dist/bootstrap.js',    
     'js/dist/templates.js',
     'js/main.js'])
      .pipe(concat('bundle.js'))
      .pipe(uglify())
      .pipe(gulp.dest('js/dist/'));
});
我的问题在哪里

错误:

未捕获错误:模板已使用较旧版本的预编译 手柄比当前运行时的手柄大。请将您的预编译器更新为 更新的版本(>=4.0.0)或将运行时降级为旧版本 版本(>=2.0.0-beta.1)

我已经使用gulp命令预编译了模板

非常感谢你

好的,我的问题出在gulp Handlebar包中,因为在包加载器中,它正在加载一个次要版本

我手动更新它,解决了我的问题。转到node_modules文件夹,找到gulp handlebar文件夹,打开package.json,并更新依赖项,如下所示:

"dependencies": {
    "gulp-util": "^3.0.4",
    "handlebars": "4.0.5",
    "through2": "^0.6.3"
  }

有一种更好的方法可以使用自述文件中介绍的特定版本的Handlebar编译模板:

确保在应用程序的
package.json
文件中指定了把手版本:

{
  "devDependencies": {
    "handlebars": "^4.0.5"
  }
}
然后将其作为gulpfile中的gulp Handlebar选项传递,以要求使用把手:

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'));
});
gulp.task('templates',function(){
gulp.src('templates/*.hbs')
.管子(把手)({
车把:需要(‘车把’)
}))
.pipe(包裹('handlebar.template()'))
.管道(申报)({
命名空间:“MyApp.templates”,
noRedeclare:true,//避免重复声明
}))
.pipe(concat('templates.js'))
.管道(大口目的地(“js/dist”);
});

我建议使用@Griffin answer,因为如果在这种情况下运行
npm update
,依赖关系可能会改变。
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'));
});