2016-01-18 10 views
6

Mam ten błąd, ale różni się między this question i moje pytanie jest to, że używam gulp zamiast chrząkać.Szablon został skompilowany ze starszą wersją Handlebars niż bieżący runtime

Po pierwsze, moje działanie rufy kierownicy to kierownica v4.0.5 (plik js).

Wyjście kierownicy -v jest 4.0.5

To jest moje 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/')); 
}); 

Main.js

"use strict"; 
var data = { title: 'This Form', name: 'Joey' }; 
var html = MyApp.templates.hellotemplate(data); 
// console.log(html); 

$(document).ready(function() { 
    $('#dynamic-content').html(html); 
}); 

gdzie można być moim problemem?

Błąd:

Uncaught Error: Template was precompiled with an older version of Handlebars than the current runtime. Please update your precompiler to a newer version (>= 4.0.0) or downgrade your runtime to an older version (>= 2.0.0-beta.1).

mam skompilowane szablony za pomocą poleceniałyk.

Dziękuję bardzo!

Odpowiedz

13

Nie ma lepszego sposobu, aby skompilować szablon stosując specyficzną wersję kierownice, które są omówione w README: https://github.com/lazd/gulp-handlebars#compiling-using-a-specific-handlebars-version

upewnij się, że określona wersja kierownicy w Twojej aplikacji package.json pliku:

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

Następnie wymagają kierownicy przekazując go jako opcja haustem-kierownice w swojej 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')); 
}); 
0

Ok, mój problem był w pakiecie gulp-handlebars, ponieważ w ładowarce pakietów ładuje się wersję dodatkową.

Aktualizuję ręcznie i rozwiązałem mój problem. Idź do node_modules folderze znaleźć haustem-Kierownice folder otwarty package.json i aktualizować dependicies tak:

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

Proponuję za pomocą odpowiedź @Griffin, bo jeśli chcesz uruchomić 'npm update' w tym przypadku zależność prawdopodobnie zmieni. – jzasnake

Powiązane problemy