Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Wiredep erroring out with "dest.on is not a function" in my gulp task?

Im trying to use Wiredep in a Gulp task to inject Bower dependencies in my index.html file. The following task (without Wiredep) runs fine.

gulp.task('build', ['copy', 'assets'], function(){

    return gulp.src('app/index.html')
    .pipe(inject(gulp.src(['dist/assets/js/*.js', 'dist/assets/css/*.css'], {read: false}), {relative: true}))
    .pipe(gulp.dest('dist'));
});

Now I tried to add Wiredep to it:

var wiredep = require('wiredep');

gulp.task('build', ['copy', 'assets'], function(){

    return gulp.src('app/index.html')
    .pipe(wiredep())
    .pipe(inject(gulp.src(['dist/assets/js/*.js', 'dist/assets/css/*.css'], {read: false}), {relative: true}))
    .pipe(gulp.dest('dist'));
});

Which results in:

[09:45:11] TypeError: dest.on is not a function
    at DestroyableTransform.Readable.pipe (C:\GIT\myApp\myApp-front\node_module
s\gulp-debug\node_modules\through2\node_modules\readable-stream\lib\_stream_read
able.js:533:8)
    at Gulp.<anonymous> (C:\GIT\myApp\myApp-front\gulpfile.js:38:6)
    at module.exports (C:\GIT\myApp\myApp-front\node_modules\gulp\node_modules\
orchestrator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (C:\GIT\myApp\myApp-front\node_modules\gulp\n
ode_modules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (C:\GIT\myApp\myApp-front\node_modules\gulp\n
ode_modules\orchestrator\index.js:214:10)
    at C:\GIT\myApp\myApp-front\node_modules\gulp\node_modules\orchestrator\ind
ex.js:279:18
    at finish (C:\GIT\myApp\myApp-front\node_modules\gulp\node_modules\orchestr
ator\lib\runTask.js:21:8)
    at C:\GIT\myApp\myApp-front\node_modules\gulp\node_modules\orchestrator\lib
\runTask.js:52:4
    at f (C:\GIT\myApp\myApp-front\node_modules\gulp\node_modules\orchestrator\
node_modules\end-of-stream\node_modules\once\once.js:17:25)
    at DestroyableTransform.onend (C:\GIT\myApp\myApp-front\node_modules\gulp\n
ode_modules\orchestrator\node_modules\end-of-stream\index.js:31:18)

I tried using Wiredep from the command line directly and it run fine. I am running on Windows, using Node v4.2.2.

EDIT If anybody encounters the same problem, then the workaround is to change the task to:

gulp.task('build', ['copy', 'assets'], function(){
    wiredep({src:'dist/index.html'});

    return gulp.src('dist/index.html')
    .pipe(inject(gulp.src(['dist/assets/js/*.js', 'dist/assets/css/*.css'], {read: false}), {relative: true}))
    .pipe(gulp.dest('dist'));
});

Note, that the index.html is copied to the dist directory prior to beeing inject.

I am still wondering why can't I use streams to wire the dependencies.

like image 935
Apokralipsa Avatar asked Nov 13 '15 08:11

Apokralipsa


1 Answers

I just ran into this problem myself. It's because of the way you're importing wiredep. You need to do the following in order for it to be piped as part of a gulp stream:

var wiredep = require('wiredep').stream;

Excluding the .stream part allows you to use wiredep as a function outside of a gulp stream.

like image 139
Greg H Avatar answered Oct 21 '22 13:10

Greg H