Gulp-autoprefixer 抛出 ReferenceError: Promise is not defined [英] Gulp-autoprefixer throwing ReferenceError: Promise is not defined

查看:16
本文介绍了Gulp-autoprefixer 抛出 ReferenceError: Promise is not defined的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试让 gulp 编译我的 sass,然后使用 gulp-autoprefixer 进行 autoprefixit,但出现错误.

I try to make a gulp compile my sass then autoprefixit with gulp-autoprefixer but i'm getting an error.

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 并且我正在使用:

I'm trying to run this Gulpfile.js and i'm using :

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

和NPM版本1.3.10

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

When i run gulp test i get this :

/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 时不起作用.我认为我的文件有问题.

I don't really know what i'm doing wrong. Is not working when i use sass or plain css. I think is something with my files.

推荐答案

我将 node.js 更新到了最新版本:

I updated node.js to the latest version using :

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

对于我的 Ubuntu 机器,如图所示这里.

for my Ubuntu machine, as shown here.

之后我使用以下方法更新了 NPM:

After that i updated NPM using :

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

如图所示这里.

现在 gulp-autoprefixer 开始工作,但我收到了来自 gulp-sass 的错误.我使用这条指令更新了它:

Now the gulp-autoprefixer start working but i got an error from gulp-sass. I updated it using this instruction :

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

找到这里.现在我有 "gulp-sass":"^2.0.4" 这解决了我所有的问题.

Found here.Now i have "gulp-sass": "^2.0.4" and this fixed all my problems.

感谢您的建议和帮助.

这篇关于Gulp-autoprefixer 抛出 ReferenceError: Promise is not defined的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆