Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook works, but then: TypeError: dest.end is not a function #459

Closed
papb opened this issue Feb 25, 2019 · 26 comments
Closed

Hook works, but then: TypeError: dest.end is not a function #459

papb opened this issue Feb 25, 2019 · 26 comments

Comments

@papb
Copy link

papb commented Feb 25, 2019

Summary of the bug

My pre-commit hook calls npm test. The test itself succeeds but then husky fails with the following error:

_stream_readable.js:628
    dest.end();
         ^

TypeError: dest.end is not a function
    at Socket.onend (_stream_readable.js:628:10)
    at Object.onceWrapper (events.js:273:13)
    at Socket.emit (events.js:187:15)
    at endReadableNT (_stream_readable.js:1094:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
npm ERR! Test failed.  See above for more details.
husky > pre-commit hook failed (add --no-verify to bypass)

My test uses cypress. I am opening the issue here on husky and not on cypress because npm test works fine when called directly, but the pre-commit hook fails.

Fully detalied steps to reproduce the bug

  1. mkdir test && cd test
  2. git init
  3. Create a .gitignore file for node_modules
  4. npm init -y
  5. npm i --save-dev husky cypress
  6. npx cypress open
  7. Close cypress
  8. Create a file cypress/integration/sample_spec.js with the following content:
describe('My First Test', function() {
  it('Does not do much!', function() {
    expect(true).to.equal(true)
  })
})
  1. Delete the other default tests just to make it run much faster: rm -r cypress/integration/examples
  2. Go to package.json and change the test script to be "cypress run"
  3. npm test - Just to observe that the test command works perfectly
  4. Add the following husky config to package.json:
{
  "husky": {
    "hooks": {
      "pre-commit": "npm test"
    }
  }
}
  1. git commit -m "Initial commit". The cypress test will run and succeed, but then, right after:
_stream_readable.js:628
    dest.end();
         ^

TypeError: dest.end is not a function
    at Socket.onend (_stream_readable.js:628:10)
    at Object.onceWrapper (events.js:273:13)
    at Socket.emit (events.js:187:15)
    at endReadableNT (_stream_readable.js:1094:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
npm ERR! Test failed.  See above for more details.
husky > pre-commit hook failed (add --no-verify to bypass)

Versions

husky: 1.3.1
node: 10.15.0
npm: 6.4.1
cypress: 3.1.5
OS: Windows_NT x64 6.1.7601

@papb
Copy link
Author

papb commented Apr 2, 2019

@ryan-snyder Thanks for the info! Maybe this is something with cypress then. I will open an issue there. Thanks.

@alexk0ch
Copy link

https://nodejs.org/api/stream.html#stream_event_end

By default, stream.end() is called on the destination Writable stream when the source Readable stream emits 'end', so that the destination is no longer writable. To disable this default behavior, the end option can be passed as false, causing the destination stream to remain open:

I had the following in my code:

testProcess.stdout.pipe(process.stdout);

basically, one stream pipes to another one which can't handle END event.
Hope this helps, for me it worked via adding options object:

testProcess.stdout.pipe(process.stdout, { end: false });

@papb
Copy link
Author

papb commented Apr 23, 2019

@alexk0ch Hello, thanks for this, looks promising, but where exactly should I add your code above? Thanks!

@alexk0ch
Copy link

yes, if cypress is piping streams there was a breaking change as far as I understand in node 10. We've started to get this error after migration to node 10. Code above is from our custom build tool.

@papb
Copy link
Author

papb commented Apr 23, 2019

@alexk0ch Hello again, sorry to bother, I still don't understand where exactly should I place that line of code you posted, can you clarify? Thanks!

@renanperalta
Copy link

renanperalta commented May 7, 2019

@alexk0ch I also dont understand where exactly should I place that line of code you posted, can you clarify? Thanks!

Note: I tried with Node 8.16, but the error continues.

@alexk0ch
Copy link

alexk0ch commented May 9, 2019

node v10.15.3, 8.12.0

"cypress": "^3.2.0",
"husky": "^2.2.0"

can't reproduce issue from @papb's steps

@papb
Copy link
Author

papb commented May 9, 2019

@alexk0ch interesting. Perhaps the new version of husky fixed this? Can you test with older versions?

@dmauldin
Copy link

@alexk0ch @papb I'm still getting this exact issue with

@papb
Copy link
Author

papb commented May 30, 2019

@dmauldin I haven't had the time to test it yet, so thanks for your comment 😁 Maybe this is an OS issue? I was using windows, what did you use? And @alexk0ch, what did you use? Thanks!

@alexk0ch
Copy link

@dmauldin I haven't had the time to test it yet, so thanks for your comment 😁 Maybe this is an OS issue? I was using windows, what did you use? And @alexk0ch, what did you use? Thanks!

osx, latest

@dmauldin
Copy link

dmauldin commented May 30, 2019

Windows, as well. Node 10.15.3. Powershell.

Also tried downgrading husky to 2.2.0 and upgrading cypress to 3.3.1 (separately), neither of which made any difference.

Wouldn't be the first time Windows gave me grief trying to do something that works in a non-windows environment. ;)

@dmauldin
Copy link

So, from the cypress issue listed above, it looks like their fix is to run in bash on windows (ie: no actual fix in cypress). It at least looks like it's a Windows issue, since every single person that says it doesn't work is doing it on Windows and everybody that can't repro is not on Windows.

Maybe it's time to close this issue and just refer people to the cypress issue?

@papb
Copy link
Author

papb commented May 30, 2019

@dmauldin I can't test right now, can you test with Git Bash for example and see if it works? Thanks a lot!

@papb
Copy link
Author

papb commented May 31, 2019

@ryan-snyder Just to make sure I understand, the cypress issue didn't solve your problem (yet), right? Did you try renanperalta's comment?

(again, I'm asking because I didn't have time to test anything yet)

@dmauldin
Copy link

@papb that fix is specifically for gitlab on Windows, which I'm not doing. I'm just using husky locally on Windows. I tried using git-bash, but it's the same failure. Using WSL bash may work, but that's a long stretch as then you have to install a metric tonne of libraries to support cypress, as even when running headless, it still needs all the X libs, gtk, etc.

I'm going to spend about another hour on this today and then move on, since the cypress team knows about it, but just aren't visibly doing anything about it. I'm hoping I may be able to find a simple change to the existing libs to get around the problem.

@papb
Copy link
Author

papb commented Jun 1, 2019

@dmauldin thanks again for all the info. Hopefully I'll have some time soon to take another look on this...

@jennifer-shehane sorry to bother but can you give your opinion on this? Do you think this is on cypress or on husky? Thanks!

@tejas-hosamani
Copy link

Hi, any update/fix on this issue?
I am using:

 "husky": {
      "version": "2.7.0",
}

"cypress": {
      "version": "3.4.1",
}

Facing the same exact issue.

Repository owner deleted a comment from tacoto12 Aug 29, 2019
Repository owner deleted a comment from tejas-hosamani Aug 29, 2019
@bahmutov
Copy link

We believe this is an issue with Cypress on Windows and not with Husky. We have an open PR that fixes this in cypress-io/cypress#5045 (fixes the direction of the STDIN pipe)

@papb
Copy link
Author

papb commented Aug 29, 2019

@bahmutov Nice!!

@papb papb closed this as completed Aug 29, 2019
@ARemaity
Copy link

Not related to husky , but im using koa in strapi to pipe pdf content to the response, i faced same , i used the solution mentioned by @alexk0ch ,and its working, thanks!

if (fs.existsSync(getUrlName)) { let createstream = fs.createReadStream(getUrlName); ctx.response.set("content-type", "application/pdf"); ctx.response.set("Content-Disposition", "attachment; filename=${fetchedfileName}.pdf"); ctx.body= ctx.req.pipe(createstream,{ end: false }); return await next(); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants
@dmauldin @bahmutov @alexk0ch @tejas-hosamani @papb @ARemaity @renanperalta and others