Gulp-autoprefixer抛出ReferenceError:Promise没有定义

我试着做一个大嘴巴编译我的sass然后用gulp gulp-autoprefixer但我得到一个错误。

 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')); }); 

我试图运行这个Gulpfile.js ,我正在使用:

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

和NPM版本1.3.10

当我运行gulp test我得到这个:

 /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) 

我真的不知道我做错了什么。 当我使用sass或普通的css时不工作。 我认为是与我的文件。

有同样的问题。 对我来说,更新节点不起作用,但在我的大文件的开头添加这个:

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

我使用以下命令将node.js更新为最新版本:

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

对于我的Ubuntu机器,如下所示。

之后,我更新了NPM使用:

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

如图所示。

现在gulp-autoprefixer开始工作,但是我从gulp-sass得到一个错误。 我使用这个指令更新它:

  1. 删除你的node_modules文件夹
  2. 从package.json文件中删除gulp-sass
  3. 从package.json文件中删除node-sass(如果你有它的话)
  4. 运行npm install gulp-sass –save-dev
  5. 根据需要更新您的Gulp任务

现在在这里find了 。现在我有了"gulp-sass": "^2.0.4" ,这就解决了我所有的问题。

感谢您的build议和帮助。

在存在package.json的项目位置安装es6-promise

 npm install es6-promise 

然后让你的gulpfile.js的第一行代码如下:

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

这不直接回答这个问题,但是当试图运行离子2教程的时候可能会遇到这个错误。

正如其他答案所指出的那样,问题是es6-promise缺失。

当试图启动离子2教程( https://github.com/driftyco/ionic2-starter-tutorial )时,我得到了同样的错误:(我的离子2版本是2.0.0-beta.25和最新的教程提交是ed9ef2fcce887e4d1c08c375c849b06b8394bad7 )

这是我尝试运行带有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) 

同样,正如其他答案所指出的,这是如何解决这个问题的:

  1. 编辑gulpfile.js并添加到第6行: require('es6-promise').polyfill();

  2. 安装缺less的依赖项: npm install es6-promise --save

这个变化之后,问题就解决了,我可以启动本地服务器了。

Interesting Posts