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

Node v4.2.1 throws error when using gulp-header #23

Closed
marcobarbosa opened this issue Oct 19, 2015 · 13 comments
Closed

Node v4.2.1 throws error when using gulp-header #23

marcobarbosa opened this issue Oct 19, 2015 · 13 comments

Comments

@marcobarbosa
Copy link

buffer.js:167
  throw new TypeError('must start with number, buffer, array or string');
  ^

TypeError: must start with number, buffer, array or string
    at fromObject (buffer.js:167:9)
    at new Buffer (buffer.js:58:10)
    at Concat.add (/.../node_modules/gulp-header/node_modules/concat-with-sourcemaps/index.js:40:15)
    at DestroyableTransform.TransformStream [as _transform] (/.../node_modules/gulp-header/index.js:49:12)
    at DestroyableTransform.Transform._read (/.../node_modules/gulp-header/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:10)
    at DestroyableTransform.Transform._write (/.../node_modules/gulp-header/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:160:12)
    at doWrite (/.../node_modules/gulp-header/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:326:12)
    at writeOrBuffer (/.../node_modules/gulp-header/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:312:5)
    at DestroyableTransform.Writable.write (/.../node_modules/gulp-header/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:239:11)
    at write (/.../node_modules/vinyl-source-stream/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:623:24)

How I'm using it (shortened for readability):

  // Create banner for Main JS file
  var javascriptBanner = ['/**',
    ' * This is the main js file',
    ' * Edited: <%= new Date() %>',
    ' */',
    '',
    'console.log("Time since you changed main.js: " + ((new Date().getTime() - <%= new Date().getTime() %> ) / 1000) + "s");',
    '',
    ''].join('\n');

module.exports = function(gulp, plugins, config, browserSync) {
  return function() {
        browserify({
            entries: [
                // ...
            ]
        })
        .transform()
        .transform()
        .bundle()
        .pipe(source(config.jsOutputFilename))
        .pipe(plugins.header(javascriptBanner))
        .pipe(gulp.dest(config.outputJsDir))
        .pipe(browserSync.stream())
 };
};

Commenting out the plugins.header line and the build works again.

Any ideas?

@dlueth
Copy link

dlueth commented Oct 28, 2015

Same here but for me the problem seems to only occur when using submodules as tasks (via 'require-dir') - but not 100% sure...

@tracker1
Copy link
Member

@marcobarbosa does it still do this if you use gulp-header as a direct require instead of via wherever plugins comes from? I haven't been able to dig into this... will try to find some time tonight.

Not sure why it would start with 4.2.1, I know there were some changes to Buffer to now be backed by UInt8Array or some such...

@alex7kom
Copy link

Same issue but it does work when wrapped in gulp-streamify.

@dlueth
Copy link

dlueth commented Oct 28, 2015

Plugins should come from a package named something with autoload-plugins which I also use. Rest assured that it is not causing this problem. Header used to work for me at least until last week and the only significant change was restructuring my tasks into separate files and require them from subdirectories via requireDir...

@dlueth
Copy link

dlueth commented Oct 29, 2015

@alex7kom in my case streamify does not solve the problem, how did you exactly do it?

@dlueth
Copy link

dlueth commented Oct 29, 2015

OK, in my case the solution was quite simple @alex7kom @marcobarbosa:

I omitted the file extension in my watch task using only src/**/* which includes directories (causing the error), changing this to src/**/*.js solved my problem

@tracker1
Copy link
Member

@marcobarbosa @alex7kom Could either of you create a simple github project that demonstrates the error in question? I'm unable to recreate, and it seems it was a misconfiguration for dueth ...

Leaving open for now, may look farther into it as time permits.

@enykeev
Copy link

enykeev commented Nov 2, 2015

As an additional clue, in my particular case I was able to work around the problem by using vinyl-buffer before and not after gulp-header:

// ...
  , browserify = require('browserify')
  , source = require('vinyl-source-stream')
  , buffer = require('vinyl-buffer')
  , sourcemaps = require('gulp-sourcemaps')
  , watchify = require('watchify')
  , header = require('gulp-header')
// ...

function Browserify() {
  var b = browserify(opts);

  if (watch) {
    b = watchify(b)
      .on('update', function () {
        bundle(b);
      });
  }

  b
    .transform(babelify.configure({
      // Make sure to change in test_compiler.js too
      optional: ['es7.classProperties']
    }))
    .on('log', gutil.log)
    ;

  return bundle(b);
}

function bundle(b) {
  return b.bundle()
    .on('error', function (error) {
      gutil.log(
        gutil.colors.cyan('Browserify') + gutil.colors.red(' found unhandled error:\n'),
        error.toString()
      );
      this.emit('end');
    })
    .pipe(source('main.js'))
    .pipe(buffer()) // <--
    .pipe(header('/* ' + buildHeader() + ' */'))
    .pipe(sourcemaps.init({ loadMaps: true }))
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('dist/js'))
    .pipe(size({
      showFiles: true
    }))
    .pipe(size({
      showFiles: true,
      gzip: true
    }));
}

@WesCossick
Copy link

@tracker1 The master branch of SimpleMDE fails due to the same error on Node 5.0.0.

@tracker1
Copy link
Member

Note to self, maybe try vinyl-buffer at the beginning?

@WesCossick thanks, will try to take a look tomorrow evening.

@marcobarbosa
Copy link
Author

Sorry for never replying this guys. Thanks a lot for the interesting discussion!

@tracker1
I'm using an almost identical setup as the one I've posted above but migrated in a Vagrant box that now uses Node 5.0.0 and the error is gone.

Despite the Node update I've also updated all of the used libs to the latest (browserify, babelify, gulp, etc).

EDIT: Not sure if I or you should close it? It'd be good to get another confirmation :)

EDIT2: Just realised that having vinyl-buffer just before the gulp-header pipe causes the problem to be gone, just like @enykeev mentioned.

.pipe(buffer())
.pipe(plugins.header())

@ibc
Copy link

ibc commented Dec 1, 2015

Same problem in JsSIP when calling gulp-header after vinyl_source_stream:

gulp.task('browserify', function() {
    return browserify([path.join(__dirname, PKG.main)], {
        standalone: PKG.title
    }).bundle()
        .pipe(vinyl_source_stream(PKG.name + '.js'))
        .pipe(header(BANNER, BANNER_OPTIONS))
        .pipe(gulp.dest('dist/'));
});

And yes, calling vinly_buffer after vinyl_source_stream magically fixes it. Do we know why? :)

grahammendick added a commit to grahammendick/navigation that referenced this issue Dec 5, 2015
After updating packages the gulp build task stopped working. The
gulp-header was the culprit (details at
gulp-community/gulp-header#23). Changed from
gulp-streamify to gulp-buffer and alls good
jeremyVignelles added a commit to jeremyVignelles/svg-pan-zoom that referenced this issue Dec 21, 2015
@tracker1
Copy link
Member

tracker1 commented May 7, 2016

published patch

@tracker1 tracker1 closed this as completed May 7, 2016
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