husky: Hook works, but then: TypeError: dest.end is not a function
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
mkdir test && cd test
git init
- Create a
.gitignore
file fornode_modules
npm init -y
npm i --save-dev husky cypress
npx cypress open
- Close cypress
- 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)
})
})
- Delete the other default tests just to make it run much faster:
rm -r cypress/integration/examples
- Go to
package.json
and change thetest
script to be"cypress run"
npm test
- Just to observe that the test command works perfectly- Add the following husky config to
package.json
:
{
"husky": {
"hooks": {
"pre-commit": "npm test"
}
}
}
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
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 26
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:
basically, one stream pipes to another one which can’t handle END event. Hope this helps, for me it worked via adding options object:
@papb I haven’t tried that fix because I’m not running cypress tests with pre-commit anymore. That fix may work though
@alexk0ch @papb I’m still getting this exact issue with
@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!
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.
I could be wrong, and maybe @alexk0ch can correct me but this looks like something that cypress would have to add to their code?
@ryan-snyder Thanks for the info! Maybe this is something with cypress then. I will open an issue there. Thanks.