gtg092x / gulp-sftp

Gulp SFTP Deploy
140 stars 61 forks source link

TypeError: file.pipe is not a function #78

Open ashlinaronin opened 6 years ago

ashlinaronin commented 6 years ago

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.

sshehata commented 6 years ago

+1

alexander-mart commented 6 years ago

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
Dan503 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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.

ashlinaronin commented 6 years ago

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

Dan503 commented 6 years ago

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.

furic-zhao commented 6 years ago

非常感谢!!!

Mindgames commented 6 years ago

@Dan503 Amazing!, thx

costacode commented 6 years ago

@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 commented 6 years ago

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

Dan503 commented 6 years ago

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 commented 6 years ago

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.

costacode commented 6 years ago

Great, did exactly that. Thanks for the reply!

unlocomqx commented 5 years ago

As @Dan503 has a working fork, you can simply install it like this npm i -D git+https://git@github.com/webksde/gulp-sftp

smemainLi commented 5 years ago

问题解决了!感谢~

lyconear commented 5 years ago

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

Dan503 commented 5 years ago

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

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

vladaman commented 4 years ago

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
unlocomqx commented 4 years ago

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

cngbinho commented 3 years ago

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