gulp-sftp icon indicating copy to clipboard operation
gulp-sftp copied to clipboard

TypeError: file.pipe is not a function

Open ashlinaronin opened this issue 7 years ago • 21 comments

Just a few days ago I started seeing this error in my Travis CI builds using gulp-sftp:

TypeError: file.pipe is not a function
    at /Users/ashlinaronin/Local Sites/portland-naacp/app/public/wp-content/themes/portland-naacp/node_modules/gulp-sftp/index.js:275:22
    at Object.async.whilst (/Users/ashlinaronin/Local Sites/portland-naacp/app/public/wp-content/themes/portland-naacp/node_modules/gulp-sftp/node_modules/async/lib/async.js:683:13)
    at /Users/ashlinaronin/Local Sites/portland-naacp/app/public/wp-content/themes/portland-naacp/node_modules/gulp-sftp/node_modules/async/lib/async.js:679:23
    at /Users/ashlinaronin/Local Sites/portland-naacp/app/public/wp-content/themes/portland-naacp/node_modules/gulp-sftp/index.js:255:21
    at SFTP._parse (/Users/ashlinaronin/Local Sites/portland-naacp/app/public/wp-content/themes/portland-naacp/node_modules/ssh2/lib/SFTP/SFTPv3.js:1093:13)
    at ChannelStream.<anonymous> (/Users/ashlinaronin/Local Sites/portland-naacp/app/public/wp-content/themes/portland-naacp/node_modules/ssh2/lib/SFTP/SFTPv3.js:72:10)
    at emitOne (events.js:96:13)
    at ChannelStream.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at ChannelStream.Readable.push (_stream_readable.js:134:10)

Everything was still working locally for me, so I tried clearing out my node_modules and re-installed them, and now I see this same error locally as well.

Given that the gulp-sftp plugin itself hasn't been updated in two years, it appears there is a new issue with one of its dependencies. Has anyone else seen this? I'm having difficulty tracking down the exact source of the problem.

ashlinaronin avatar Dec 31 '17 23:12 ashlinaronin

+1

sshehata avatar Jan 05 '18 12:01 sshehata

This error was started after update Gulp to version 4.0.0 from 3.9.1

TypeError: file.pipe is not a function
    at /foobar/node_modules/gulp-sftp/index.js:275:22

alexander-mart avatar Jan 09 '18 00:01 alexander-mart

Specifically it started occurring when Gulp 4 updated from gulp-4.0-alpha.2 to gulp-4.0-alpha.3.

I've had issues with other components as well due to this change (browserify and gulp-modernizr broke for me as well). Unfortunatly it doesn't seem possible to download gulp-4.0-alpha.2 through npm so we're kinda stuck :/

Dan503 avatar Jan 09 '18 07:01 Dan503

From one of the Gulp core contributors:

we removed the pipe method that existed on a Vinyl object because the API was very bad and did not do what people expected. Plugins now need to be handling null/streaming/buffer contents specifically instead of that opaque file.pipe API

Dan503 avatar Jan 09 '18 21:01 Dan503

vinyl-ftp has a similar looking ftp upload file. I was able to get it working after taking a bit of inspiration from this file: https://github.com/morris/vinyl-ftp/blob/master/lib/ftp.js

First, create a local copy of the gulp-sftp index.js file and save it into your version control.

Find this line: file.pipe(stream); // start upload it should be on line 284 of index.js

Replace it with this:

// start upload
if ( file.isStream() ) {
    file.contents.pipe( stream );
} else if ( file.isBuffer() ) {
    stream.end( file.contents );
}

Now reference your new version of gulp-sftp instead of the npm version and it should magically start working again.

Dan503 avatar Jan 10 '18 01:01 Dan503

Nice, @Dan503! Submit as a PR to this project?

ashlinaronin avatar Jan 10 '18 05:01 ashlinaronin

I might do it later. I doubt it would do much good though. The owner hasn't made any alterations to this thing in over 2 whole years.

Dan503 avatar Jan 10 '18 05:01 Dan503

非常感谢!!!

furic-zhao avatar Jan 17 '18 11:01 furic-zhao

@Dan503 Amazing!, thx

Mindgames avatar Jan 19 '18 05:01 Mindgames

@Dan503 I made changes on the index.js and it certainly fixes the Gulp 4 compatibility. Got a question about the reference to the new version of gulp-sftp (instead of the npm version). Where do you make that change?

costacode avatar Mar 26 '18 15:03 costacode

@Dan503 Found it. Yeah, reference is done on the actual gulpfile, where I now call my local index.js, instead of the npm version.

costacode avatar Mar 26 '18 16:03 costacode

First, create a local copy of the gulp-sftp index.js file and save it into your version control.

@costacode the change is made to the copy you made of the gulp-sftp index.js file.

Dan503 avatar Mar 26 '18 21:03 Dan503

the reference to the new version of gulp-sftp (instead of the npm version). Where do you make that change?

Oh right, yeah you add that reference to the gulp file you are using gulp-sftp in.

So instead of

import sftp from "gulp-sftp"

You would have

import sftp from "./gulp-sftp-copy"

Or something like that. The path would be different depending on where you placed the file.

Dan503 avatar Mar 26 '18 21:03 Dan503

Great, did exactly that. Thanks for the reply!

costacode avatar Mar 27 '18 09:03 costacode

As @Dan503 has a working fork, you can simply install it like this npm i -D git+https://[email protected]/webksde/gulp-sftp

unlocomqx avatar Dec 20 '18 12:12 unlocomqx

问题解决了!感谢~

smemainLi avatar Jan 23 '19 02:01 smemainLi

my problem is solved, thx!!! it is worked!!

lyconear avatar May 25 '19 16:05 lyconear

It's best not to post comments like "thanks" and "+1".

You can show appreciation through using the reaction emojis on the individual comments.

Dan503 avatar May 25 '19 22:05 Dan503

Is there any fix for this? I am still experiencing same issue.

gulp-sftp version: 0.1.5

gulp --version
CLI version: 2.2.0
Local version: 4.0.0

vladaman avatar Dec 30 '19 16:12 vladaman

@vladaman Try this https://github.com/gtg092x/gulp-sftp/issues/78#issuecomment-448987310 it's a working fork by webksde

unlocomqx avatar Dec 30 '19 16:12 unlocomqx

# 78 (comentário) solved my problem thanks +1

cngbinho avatar Nov 13 '20 17:11 cngbinho