2015-09-09 21 views
80

Próbuję zrobić łyk kompilować mój sass to autoprefixit z gulp-autoprefixer, ale dostaję błąd.Gulp-autoprefixer throwing ReferenceError: Obietnica nie jest zdefiniowana

var gulp = require('gulp'), 
    sass = require('gulp-sass'), 
    autoprefixer = require('gulp-autoprefixer'); 

gulp.task('test', function(){ 
    gulp.src('_sass/main.sass') 
     .pipe(sass()) 
     .pipe(autoprefixer()) 
     .pipe(gulp.dest('./assets/css')); 
}); 

Próbuję uruchomić ten Gulpfile.js i używam:

"gulp": "~3.9.0", 
"gulp-sass": "~2.0.4", 
"gulp-autoprefixer": "~3.0.1", 

i NPM wersję 1.3.10

Kiedy biegnę gulp test uzyskać to:

/home/matei/Tests/test-4/node_modules/gulp-autoprefixer/node_modules/postcss/lib/lazy-result.js:152 
     this.processing = new Promise(function (resolve, reject) { 
          ^
ReferenceError: Promise is not defined 
    at LazyResult.async (/home/matei/Tests/test-4/node_modules/gulp-autoprefixer/node_modules/postcss/lib/lazy-result.js:152:31) 
    at LazyResult.then (/home/matei/Tests/test-4/node_modules/gulp-autoprefixer/node_modules/postcss/lib/lazy-result.js:75:21) 
    at DestroyableTransform._transform (/home/matei/Tests/test-4/node_modules/gulp-autoprefixer/index.js:28:13) 
    at DestroyableTransform.Transform._read (/home/matei/Tests/test-4/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:10) 
    at DestroyableTransform.Transform._write (/home/matei/Tests/test-4/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:160:12) 
    at doWrite (/home/matei/Tests/test-4/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:326:12) 
    at writeOrBuffer (/home/matei/Tests/test-4/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:312:5) 
    at DestroyableTransform.Writable.write (/home/matei/Tests/test-4/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:239:11) 
    at write (/home/matei/Tests/test-4/node_modules/gulp-sass/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:623:24) 
    at flow (/home/matei/Tests/test-4/node_modules/gulp-sass/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:632:7) 

Naprawdę nie wiem, co robię źle. Nie działa, gdy używam sass lub zwykłego css. Myślę, że jest coś z moimi plikami.

+1

Nie jestem pewien, co to ma wspólnego z Sass (lub CSS), gdy błąd jest zgłaszany przez Autoprefixer. – cimmanon

+2

Nie jestem pewien, czy to rozwiązanie, czy nie .... ale twoja wersja NPM jest nieaktualna. Spróbuj aktualizować npm i wszystkie swoje pakiety, w przeszłości działałem tak dziwacznie, podczas gdy starsze kompilacje działają. –

Odpowiedz

65

zaktualizowałem node.js do najnowszej wersji przy użyciu:

# Using Ubuntu 
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash - 
sudo apt-get install -y nodejs 

na moim komputerze Ubuntu, jak pokazano here.

Potem przy użyciu zaktualizowanego NPM:

sudo npm cache clean -f 
sudo npm install -g n 
sudo n stable 

Jak pokazano here.

Teraz działa gulp-autoprefixer, ale mam błąd z gulp-sass. Po zaktualizowaniu go za pomocą tej instrukcji:

  1. usuwać swoich node_modules folderowi
  2. Usuń haustem-Sass z pliku package.json
  3. Remove node-Sass z pliku package.json (jeśli masz go tam)
  4. Run npm zainstalować haustem-Sass flagą --save-dev
  5. Aktualizacja zadanie Twój haustem wymagane

Znaleziony here .Teraz mam "gulp-sass": "^2.0.4" i to naprawiło wszystkie moje problemy.

Dzięki za porady i pomoc.

+11

Możesz otrzymać 'węzeł-sass' działający z' npm rebuild node-sass' po uaktualnieniu węzła. – xiuyuan

+0

po prostu działało świetnie. dzięki. również komunikat konsoli prosi o uruchomienie tego polecenia w przypadku napotkania błędu podczas wykonywania zadania –

+1

Jest to rzeczywiście problem z wersją NodeJS, zobacz https://github.com/sindresorhus/gulp-autoprefixer/issues/45 – tricasse

78

Miał ten sam problem. Dla mnie, aktualizowanie węzeł nie działał, ale dodanie tego na samym początku mojego gulpfile zrobił:

require('es6-promise').polyfill(); 
+4

To rozwiązało problem. –

+2

To działało również dla mnie. Każdy pomysł, dlaczego? – Barryman9000

+0

Co się stało? Wczoraj wszystko było poprawnie budowane ... –

29

Install ES6 obietnicy w ur lokalizacji projektu, gdzie istnieje package.json

npm install es6-promise 

Następnie zrób pierwsza linia swoimi gulpfile.js być następujący kod:

var Promise = require('es6-promise').Promise; 
2

to nie jest odpowiedź na pytanie bezpośrednio, ale może to być przydatne dla osób, które się tego błędu podczas próby uruchomienia jonowa 2 samouczek.

Jak wskazują inne odpowiedzi, problem polega na tym, że brakuje es6-promise.

Mam ten sam błąd, gdy próbuje uruchomić samouczek jonowy 2 (https://github.com/driftyco/ionic2-starter-tutorial): (moja wersja to 2.0.0 jonowa 2-beta.25 i najnowszy poradnik popełnić jest ed9ef2fcce887e4d1c08c375c849b06b8394bad7)

To stos prześledzić mam kiedy próbuje uruchomić aplikację z ionic serve:

Running 'serve:before' gulp task before serve 
[18:37:00] Starting 'clean'... 
[18:37:01] Finished 'clean' after 1.02 s 
[18:37:01] Starting 'watch'... 
[18:37:01] Starting 'sass'... 
[18:37:01] Starting 'html'... 
[18:37:01] Starting 'fonts'... 
[18:37:01] Starting 'scripts'... 
[18:37:01] Finished 'scripts' after 62 ms 
[18:37:01] Finished 'html' after 72 ms 
[18:37:01] Finished 'fonts' after 77 ms 
Caught exception: 
ReferenceError: Promise is not defined 
    at LazyResult.async (/home/stitakis/dev/playground/ionic2/myTutorial/node_modules/ionic-gulp-sass-build/node_modules/gulp-autoprefixer/node_modules/postcss/lib/lazy-result.js:157:31) 
    at LazyResult.then (/home/stitakis/dev/playground/ionic2/myTutorial/node_modules/ionic-gulp-sass-build/node_modules/gulp-autoprefixer/node_modules/postcss/lib/lazy-result.js:79:21) 
    at DestroyableTransform._transform (/home/stitakis/dev/playground/ionic2/myTutorial/node_modules/ionic-gulp-sass-build/node_modules/gulp-autoprefixer/index.js:24:6) 
    at DestroyableTransform.Transform._read (/home/stitakis/dev/playground/ionic2/myTutorial/node_modules/ionic-gulp-sass-build/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:159:10) 
    at DestroyableTransform.Transform._write (/home/stitakis/dev/playground/ionic2/myTutorial/node_modules/ionic-gulp-sass-build/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:147:83) 
    at doWrite (/home/stitakis/dev/playground/ionic2/myTutorial/node_modules/ionic-gulp-sass-build/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:313:64) 
    at writeOrBuffer (/home/stitakis/dev/playground/ionic2/myTutorial/node_modules/ionic-gulp-sass-build/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:302:5) 
    at DestroyableTransform.Writable.write (/home/stitakis/dev/playground/ionic2/myTutorial/node_modules/ionic-gulp-sass-build/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:241:11) 
    at DestroyableTransform.ondata (/home/stitakis/dev/playground/ionic2/myTutorial/node_modules/ionic-gulp-sass-build/node_modules/gulp-sass/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:531:20) 
    at DestroyableTransform.EventEmitter.emit (events.js:95:17) 

Ponownie, jak wskazano przez innych odpowiedzi, to jak rozwiązać ten problem:

  1. edit gulpfile.js i dodać w wierszu 6: require('es6-promise').polyfill();

  2. zainstalowania brakujących zależnościach z: npm install es6-promise --save

Po tej zmiany, problem został rozwiązany i udało mi się uruchomić serwer lokalny .

+0

Naprawiono problem dla mnie, wszystko co musiałem zrobić to użyć instalacji np6 esit-obietnica z - zapisz i użyj tego wymagania z .pollyfill, używając .Promise() jak w awnser powyżej nie działa dla mnie. – killstreet

Powiązane problemy