taptapship / wiredep

Wire Bower dependencies to your source code.
MIT License
1.15k stars 142 forks source link

Error, if use stream and empty file #219

Open vitstr opened 9 years ago

vitstr commented 9 years ago

Hi, guys!

I'm use:

I have two scss file in 'app/assets/styles/' folder. One file is empty. If run this code, wiredep return error.

var gulp = require('gulp');
var gulpLoadPlugins = require('gulp-load-plugins');
var wiredepGulp = require('wiredep').stream;
var $ = gulpLoadPlugins();

gulp.task('wiredep', function () {
    return gulp.src('app/assets/styles/*.scss', {base: 'src'})
        .pipe(wiredepGulp())
        .pipe(gulp.dest('app'));
});

Error text:

events.js:141
      throw er; // Unhandled 'error' event
      ^

TypeError: must start with number, buffer, array or string
    at fromObject (buffer.js:167:9)
    at new Buffer (buffer.js:58:10)
    at DestroyableTransform._transform (/Users/xxx/ownCloud/Projects/base-layouts/node_modules/wiredep/wiredep.js:135:23)
    at DestroyableTransform.Transform._read (/Users/xxx/ownCloud/Projects/base-layouts/node_modules/wiredep/node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at DestroyableTransform.Transform._write (/Users/xxx/ownCloud/Projects/base-layouts/node_modules/wiredep/node_modules/readable-stream/lib/_stream_transform.js:172:12)
    at doWrite (/Users/xxx/ownCloud/Projects/base-layouts/node_modules/wiredep/node_modules/readable-stream/lib/_stream_writable.js:237:10)
    at writeOrBuffer (/Users/xxx/ownCloud/Projects/base-layouts/node_modules/wiredep/node_modules/readable-stream/lib/_stream_writable.js:227:5)
    at DestroyableTransform.Writable.write (/Users/xxx/ownCloud/Projects/base-layouts/node_modules/wiredep/node_modules/readable-stream/lib/_stream_writable.js:194:11)
    at DestroyableTransform.ondata (/Users/xxx/ownCloud/Projects/base-layouts/node_modules/readable-stream/lib/_stream_readable.js:578:20)
    at emitOne (events.js:77:13)

but, if run this code (without gulp stream), build is successful

gulp.task('wiredep', function () {
    require('wiredep')({
        src: 'app/assets/styles/*.scss'
    });
});

It is bug or feature?) Thanks.

zfarrugia commented 9 years ago

Im having a similar/same issue:

node -v :: v5.0.0 gulp -v :: 3.9.0 wiredep :: 2.2.2

events.js:141 throw er; // Unhandled 'error' event ^

Error: Error: angular is not installed. Try running bower install. at /Users/zac/PhpstormProjects/myApp/node_modules/wiredep/wiredep.js:30:56 at /Users/zac/PhpstormProjects/myApp/node_modules/wiredep/lib/detect-dependencies.js:145:29 at forOwn (/Users/zac/PhpstormProjects/myApp/node_modules/wiredep/node_modules/lodash/dist/lodash.js:2106:15) at Function.forEach (/Users/zac/PhpstormProjects/myApp/node_modules/wiredep/node_modules/lodash/dist/lodash.js:3303:9) at detectDependencies (/Users/zac/PhpstormProjects/myApp/node_modules/wiredep/lib/detect-dependencies.js:34:7) at wiredep (/Users/zac/PhpstormProjects/myApp/node_modules/wiredep/wiredep.js:70:39) at DestroyableTransform._transform (/Users/zac/PhpstormProjects/myApp/node_modules/wiredep/wiredep.js:135:34) at DestroyableTransform.Transform._read (/Users/zac/PhpstormProjects/myApp/node_modules/wiredep/node_modules/readable-stream/lib/_stream_transform.js:184:10) at DestroyableTransform.Transform._write (/Users/zac/PhpstormProjects/myApp/node_modules/wiredep/node_modules/readable-stream/lib/_stream_transform.js:172:12) at doWrite (/Users/zac/PhpstormProjects/myApp/node_modules/wiredep/node_modules/readable-stream/lib/_stream_writable.js:237:10)

corin12355 commented 8 years ago

Same issue here

gulp -v CLI version = 0.3.0 Local version = 3.9.0

node -v = v5.0.0

wiredep = 3.0.0-beta

events.js:141 throw er; // Unhandled 'error' event ^

TypeError: must start with number, buffer, array or string at fromObject (buffer.js:167:9) at new Buffer (buffer.js:58:10) at DestroyableTransform._transform (/home/sgw/public_html/sag/node_modules/wiredep/wiredep.js:135:23) at DestroyableTransform.Transform._read (/home/sgw/public_html/sag/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10) at DestroyableTransform.Transform._write (/home/sgw/public_html/sag/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:12) at doWrite (/home/sgw/public_html/sag/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:237:10) at writeOrBuffer (/home/sgw/public_html/sag/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:227:5) at DestroyableTransform.Writable.write (/home/sgw/public_html/sag/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:194:11) at write (/home/sgw/public_html/sag/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:623:24) at flow (/home/sgw/public_html/sag/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:632:7)

baerkins commented 8 years ago

Same exact thing as @corin12355 (same versions and all)

brousalis commented 8 years ago

The fix can be made in wiredep.js line 130:

opts.stream = {
   src: file.contents.toString() || "",

it tries to load the stream with undefined because the file is blank, which causes the TypeError.

corin12355 commented 8 years ago

@iamhexcoder I found a fix, basically if a file is empty then it'll error out with a non-descriptive error. Just check your manifest for empty files.

coldkite commented 8 years ago

agree with @brousalis actually it could be anything except null or empty string so, || "" not works. something like || " " works

akleiber commented 8 years ago

quickfix https://www.npmjs.com/package/gulp-clip-empty-files

mbjacket81 commented 8 years ago

I like your solution akleiber but coldkite's solution worked for me as well. Thanks!

eddiemonge commented 8 years ago

PRs welcome

dmishh commented 8 years ago

Got the same issue with an empty Google Analytics verification html file. Added one space to it as a temporary solution