node.js Gulp-autoprefixer 抛出 ReferenceError:未定义承诺
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32490328/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gulp-autoprefixer throwing ReferenceError: Promise is not defined
提问by Matei
I try to make a gulp compile my sass then autoprefixit with gulp-autoprefixerbut i'm getting an error.
我尝试让 gulp 编译我的 sass 然后使用 autoprefixitgulp-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'));
});
I'm trying to run this Gulpfile.jsand i'm using :
我正在尝试运行它Gulpfile.js并且我正在使用:
"gulp": "~3.9.0",
"gulp-sass": "~2.0.4",
"gulp-autoprefixer": "~3.0.1",
and NPM version 1.3.10
和 NPM 版本 1.3.10
When i run gulp testi get this :
当我跑步时,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)
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.
我真的不知道我做错了什么。当我使用 sass 或普通 css 时不起作用。我认为我的文件有问题。
采纳答案by Matei
I updated node.js to the latest version using :
我使用以下命令将 node.js 更新到最新版本:
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
for my Ubuntu machine, as shown here.
对于我的Ubuntu的机器,如图所示这里。
After that i updated NPM using :
之后,我使用以下方法更新了 NPM:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
As shown here.
如图所示这里。
Now the gulp-autoprefixerstart working but i got an error from gulp-sass. I updated it using this instruction :
现在gulp-autoprefixer开始工作,但我从gulp-sass. 我使用以下说明更新了它:
- Delete your node_modules folder
- Remove gulp-sass from your package.json file
- Remove node-sass from your package.json file (if you have it in there)
- Run npm install gulp-sass --save-dev
- Update your Gulp task as required
- 删除您的 node_modules 文件夹
- 从 package.json 文件中删除 gulp-sass
- 从 package.json 文件中删除 node-sass(如果你有的话)
- 运行 npm install gulp-sass --save-dev
- 根据需要更新您的 Gulp 任务
Found here.Now i have "gulp-sass": "^2.0.4"and this fixed all my problems.
在这里找到。现在我有了"gulp-sass": "^2.0.4",这解决了我所有的问题。
Thanks for advice and help.
感谢您的建议和帮助。
回答by Chris Searles
Had the same issue. For me, updating node didn't work but adding this at the very beginning of my gulpfile did:
有同样的问题。对我来说,更新节点不起作用,但在我的 gulpfile 的最开始添加它做了:
require('es6-promise').polyfill();
回答by Hari Gillala
Install es6-promise in ur project location where package.json exists
在 package.json 所在的项目位置安装 es6-promise
npm install es6-promise
Then make the first line of your gulpfile.js be the following code:
然后让你的 gulpfile.js 的第一行代码如下:
var Promise = require('es6-promise').Promise;
回答by stitakis
This does not answer the question directly but it might be useful for people that get this error when trying to run the ionic 2 tutorial.
这不会直接回答问题,但对于在尝试运行 ionic 2 教程时遇到此错误的人来说可能很有用。
As pointed by other answers the problem is that es6-promiseis missing.
正如其他答案所指出的那样,问题在于es6-promise缺少。
I got the same error when trying to start the ionic 2 tutorial (https://github.com/driftyco/ionic2-starter-tutorial): (my ionic 2 version is 2.0.0-beta.25 and latest tutorial commit is ed9ef2fcce887e4d1c08c375c849b06b8394bad7)
我在尝试启动 ionic 2 教程(https://github.com/driftyco/ionic2-starter-tutorial)时遇到了同样的错误:(我的 ionic 2 版本是 2.0.0-beta.25,最新的教程提交是 ed9ef2fcce887e4d1c08c375c849b06b8394bad7 )
This is the stack trace I got when trying to run the app with ionic serve:
这是我在尝试使用以下命令运行应用程序时得到的堆栈跟踪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)
Again, as pointed by other answers, this is how to solve this:
同样,正如其他答案所指出的,这是解决此问题的方法:
edit gulpfile.js and add in line 6:
require('es6-promise').polyfill();install the missing dependency with:
npm install es6-promise --save
编辑 gulpfile.js 并在第 6 行添加:
require('es6-promise').polyfill();安装缺少的依赖项:
npm install es6-promise --save
After this changes, the problem was fixed and I was able to start the local server.
更改后,问题得到解决,我能够启动本地服务器。

