Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: Promise is not defined #30

Closed
lmartins opened this issue Aug 29, 2015 · 16 comments
Closed

ReferenceError: Promise is not defined #30

lmartins opened this issue Aug 29, 2015 · 16 comments

Comments

@lmartins
Copy link

Just trying out PostCSS and right out the gate bumped into an issue im not sure why.

Whenever I change the CSS file, with postcss-nested enabled, i get:

/Users/luismartins/Sites/LAB/postcss/node_modules/gulp-postcss/node_modules/postcss/lib/lazy-result.js:152
        this.processing = new Promise(function (resolve, reject) {
                              ^
ReferenceError: Promise is not defined
    at LazyResult.async (/Users/luismartins/Sites/LAB/postcss/node_modules/gulp-postcss/node_modules/postcss/lib/lazy-result.js:152:31)
    at LazyResult.then (/Users/luismartins/Sites/LAB/postcss/node_modules/gulp-postcss/node_modules/postcss/lib/lazy-result.js:75:21)
    at Transform.stream._transform (/Users/luismartins/Sites/LAB/postcss/node_modules/gulp-postcss/index.js:45:8)
    at Transform._read (_stream_transform.js:179:10)
    at Transform._write (_stream_transform.js:167:12)
    at doWrite (_stream_writable.js:226:10)
    at writeOrBuffer (_stream_writable.js:216:5)
    at Transform.Writable.write (_stream_writable.js:183:11)
    at write (/Users/luismartins/Sites/LAB/postcss/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:623:24)
    at flow (/Users/luismartins/Sites/LAB/postcss/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:632:7)

My gulpfile.js is pretty vanilla atm:

var gulp = require('gulp');
var nestedcss = require('postcss-nested');
    // browserSync = require('browser-sync'),
    // reload      = browserSync.reload;


gulp.task('css', function () {
    var postcss = require('gulp-postcss');
    var processors = [
        nestedcss
    ];
    return gulp.src('src/**/*.css')
        .pipe( postcss( processors ) )
        .pipe( gulp.dest('build/') );
});



// Watch
gulp.task('default', function() {

    gulp.watch('src/**/*.css', ['css']);

});

The css file only has a standard css declaration in it.

Any tips?

@TrySound
Copy link
Member

@lmartins You can update node.js to 0.12 or install and call before all postcss requires

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

@lmartins
Copy link
Author

Thank you for the ultra fast reply.
Cheers

Sent from my iPhone

On 29/08/2015, at 20:15, Bogdan Chadkin notifications@github.com wrote:

@lmartins You can update node.js to 0.12 or install and call before all postcss requires

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

Reply to this email directly or view it on GitHub.

@aniketnandan
Copy link

I am having node version 0.10.13 but still it gives me the same error.

@TrySound
Copy link
Member

@lmartins require('es6-promise').polyfill(); should be first statement in your js file.

@shinnn
Copy link

shinnn commented Sep 21, 2015

@lmartins @aniketnandan I strongly recommend to upgrade Node to v4.1.0 since v0.x is a really out-of-date version.

@lmartins
Copy link
Author

Yup, I always forget to update node on my machines. Thanks.

shinnn referenced this issue in deoxxa/duplexer2 Sep 22, 2015
At least we should check if duplexer2 works correctly on the latest
stable Node.
@Gillala
Copy link

Gillala commented Feb 5, 2016

My gulpfile.js contains, I am using node version 5.5.0

`//---------------------------------------------------------
// GULP CONFIGURATION
//---------------------------------------------------------

var gulp = require('gulp'),
sass = require('gulp-sass'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
minCss = require('gulp-minify-css'),
autoprefixer = require('gulp-autoprefixer'),
chmod = require('gulp-chmod'),
rename = require('gulp-rename'),
rimraf = require('rimraf'),
plumber = require('gulp-plumber'),
project = require('./project.json');

var webroot = './' + project.webroot + '/';

var paths = {
webroot: webroot,

appJsSrc: webroot + "js/**/*.js",
appCssSrc: webroot + "css/**/*.css",
appScssSrc: webroot + "scss/**/*.scss",

libCssSrc: webroot + "lib/**/*.css",
libJsSrc: webroot + "lib/**/*.js",

libappJsSrc: webroot + "lib/app/*.js",

jsDest: webroot + "js/",
cssDest: webroot + "css/",

cssFile: "site.css",
jsFile: "site.js"

};

//---------------------------------------------------------
// TASKS
//---------------------------------------------------------

// CLEAN

gulp.task('clean:js', function (cb) {
return rimraf(paths.jsDest, cb);
});

gulp.task('clean:css', function (cb) {
return rimraf(paths.cssDest, cb);
});

gulp.task('clean', ['clean:js', 'clean:css']);

// CCS

gulp.task('css:sass', function () {
return gulp.src(paths.appScssSrc)
.pipe(plumber())
.pipe(sass({
outputStyle: 'compressed',
sourceComments: 'map'
}))
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['> 1%', 'IE 9'],
cascade: false
}))
.pipe(chmod(666))
.pipe(gulp.dest(paths.cssDest));
});

gulp.task('css:concat', ['css:sass'], function () {
return gulp.src(['./wwwroot/css/**/main.css', '!./wwwroot/css/site.css'])
.pipe(concat(paths.cssFile))
.pipe(chmod(666))
.pipe(gulp.dest(paths.cssDest));
});

gulp.task('css:min', ['css:concat'], function () {
return gulp.src(paths.cssDest + paths.cssFile)
.pipe(minCss())
.pipe(rename({ suffix: '.min' }))
.pipe(chmod(666))
.pipe(gulp.dest(paths.cssDest));
});

// JS
gulp.task('js:libapp', function () {
return gulp.src(paths.libappJsSrc)
.pipe(concat(paths.jsFile))
.pipe(chmod(666))
.pipe(gulp.dest(paths.jsDest));
});

gulp.task('js:concat', ['js:libapp'], function () {
return gulp.src(paths.appJsSrc + paths.jsFile)
.pipe(concat(paths.jsFile))
.pipe(chmod(666))
.pipe(gulp.dest(paths.jsDest));
});

gulp.task('js:min',['js:concat'], function () {
return gulp.src(paths.jsDest + paths.jsFile)
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(chmod(666))
.pipe(gulp.dest(paths.jsDest));
});

gulp.task('min', ['css:min','js:min']);

// Watches
gulp.task('watch:sass', function () {
gulp.watch(paths.appScssSrc, ['css:concat']);
});

gulp.task('watch:js', function () {
gulp.watch(paths.libappJsSrc, ['js:libapp']);
});

gulp.task('watch:all', ['watch:sass','watch:js']);

// No default task as yet
gulp.task('default', function() {

});
`

I am using node version 5.5.0. I am getting the Promise Library not installed error.

So how do I put the first line in gulpfile.js ,

is it like below:
require('es6-promise').polyfill();???

@TrySound
Copy link
Member

TrySound commented Feb 5, 2016

@Gillala Which exactly error did you get? Show error log

@Gillala
Copy link

Gillala commented Feb 5, 2016

C:\Projects\DEV\XXXXXX.ECD.UI\src\XXXXXX.ECD.UI\node_modules\gulp-autoprefixer\node_modules\postcss\lib\lazy-result.js:157 this.processing = new Promise(function (resolve, reject) { ^ ReferenceError: Promise is not defined at LazyResult.async (C:\Projects\DEV\XXXXXX.ECD.UI\src\XXXXXX.ECD.UI\node_modules\gulp-autoprefixer\node_modules\postcss\lib\lazy-result.js:157:31) at LazyResult.then (C:\Projects\DEV\XXXXXX.ECD.UI\src\XXXXXX.ECD.UI\node_modules\gulp-autoprefixer\node_modules\postcss\lib\lazy-result.js:79:21) at DestroyableTransform._transform (C:\Projects\DEV\XXXXXX.ECD.UI\src\XXXXXX.ECD.UI\node_modules\gulp-autoprefixer\index.js:24:6) at DestroyableTransform.Transform._read (C:\Projects\DEV\XXXXXX.ECD.UI\src\XXXXXX.ECD.UI\node_modules\gulp-autoprefixer\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:172:10) at DestroyableTransform.Transform._write (C:\Projects\DEV\XXXXXX.ECD.UI\src\XXXXXX.ECD.UI\node_modules\gulp-autoprefixer\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:160:12) at doWrite (C:\Projects\DEV\XXXXXX.ECD.UI\src\XXXXXX.ECD.UI\node_modules\gulp-autoprefixer\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:335:12) Process terminated with code 8. at writeOrBuffer (C:\Projects\DEV\XXXXXX.ECD.UI\src\XXXXXX.ECD.UI\node_modules\gulp-autoprefixer\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:321:5) at DestroyableTransform.Writable.write (C:\Projects\DEV\XXXXXX.ECD.UI\src\XXXXXX.ECD.UI\node_modules\gulp-autoprefixer\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:248:11) at write (C:\Projects\DEV\XXXXXX.ECD.UI\src\XXXXXX.ECD.UI\node_modules\gulp-sass\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:623:24) at flow (C:\Projects\DEV\XXXXXX.ECD.UI\src\XXXXXX.ECD.UI\node_modules\gulp-sass\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:632:7)

@TrySound
Copy link
Member

TrySound commented Feb 5, 2016

@Gillala Are you sure you use node5? Run please node -v

@Gillala
Copy link

Gillala commented Feb 5, 2016

when I run command node -v I get v5.5.0

@ai
Copy link
Member

ai commented Feb 5, 2016

@kasparsklavins
Copy link

Having the same problem on node v.5.7

@TrySound
Copy link
Member

@kasparsklavins It's not postcss issue. Maybe some part of your code removed global Promise object. Try to add polyfill.

@kasparsklavins
Copy link

It's ran using postcss-cli.
One cant just require polyfill from the commandline

@kasparsklavins
Copy link

Solved this by overriding postcss-cli/bin/postcss

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants