question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Node v4.2.1 throws error when using gulp-header

See original GitHub issue
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?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
enykeevcommented, 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
    }));
}
0reactions
tracker1commented, May 7, 2016

published patch

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with package.json? · Issue #2524 - GitHub
I have install node 5.9.1 cleanly and gotten almost same result with 'npm install'. However I cannot build Mattermost. ERROR in ./~/css-loader ...
Read more >
node.js - Installing puppeteer throws error with "Failed to ...
Failed at the puppeteer@4.0.1 install script 'node install.js'. npm ERR! Make sure you have the latest version of node.js and npm installed.
Read more >
Problems with rfbrowser init - Browser - Robot Framework
I have try installation at company network and I have problems with grpc > grpc@1.24.3 install ...
Read more >
Node v4.2.1 (LTS)
When a server queues a large amount of data to send to a client over a pipelined HTTP connection, the underlying socket may...
Read more >
How to Throw Exceptions in Node.js - Rollbar
Node.js Throw Exception; How do you protect your application against exceptions? Wrapping Up; Track, Analyze and Manage Errors With Rollbar.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found