Error: Premature close
See original GitHub issuePrerequisites
- I confirm my issue is not in the opened issues
- I confirm the Frequently Asked Questions didn’t contain the answer to my issue
Environment check
- I’m using the latest
msw
version - I’m using Node.js version 14 or higher
Node.js version
v16.14.1
Reproduction repository
Reproduction steps
I use Vitest test and use some Polyfill:
- node-fetch v3.2.3
- abort-controller v3.0.0
- formdata-node v4.3.2
Current behavior
When I run the test, there is a high probability that this error will occur:
❯ __tests__/main.spec.ts (2)
❯ Test methods (2)
√ GET request
× POST request
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL __tests__/main.spec.ts > Test methods > POST request
Error: Premature close
❯ NodeClientRequest.emit node:events:402:35
❯ NodeClientRequest.emit node_modules/.pnpm/@mswjs+interceptors@0.15.1/node_modules/@mswjs/interceptors/lib/interceptors/ClientRequest/NodeClientRequest.js:309:38
❯ Socket.socketCloseListener node:_http_client:423:9
❯ Socket.emit node:events:402:35
❯ TCP.<anonymous> node:net:687:12
Expected behavior
No errors
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top Results From Across the Web
npm ERR! premature close when using npm install
In my case, the package I was trying to install had a dependency on a Git repository that didn't have a package.json defined...
Read more >"premature close" error during npm install from git url #1 - GitHub
I know/see, that this repo doesn't have package.json, and I do npm install https://github.com/coryetzkorn/state-svg-defs.git Also tried ssh.
Read more >[Gatling 3.0.-RC2] Premature close - Google Groups
If the duration passed into holdFor() is not long enough for all requests to be processed with a response, a number "premature close"...
Read more >Avoiding premature closure in sequential diagnosis - PubMed
On the other hand, the reasoner must be careful to avoid the error, known as premature closure, of accepting a diagnosis before it...
Read more >Premature close : r/deemix - Reddit
Can anyone explain what this error means: Premature close. I downloaded 37 songs, this error was shown by 10 songs.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m getting the same error with jest when upgrading from
v0.36.3
.In my case:
v0.36.3
didn’t trigger the issue (my initial version)v0.36.8
didn’t trigger the issuev0.38.0
trigger the issuev0.38.1
trigger the issuev0.38.2
trigger the issuev0.39.2
trigger the issueBy looking into the changelog of the v0.38.0, it could linked to the interceptor upgrade.
I’m seeing a weird error that seems unrelated: when doing an
axios.put
, the request hangs forever unless I set a timeout. msw doesn’t properly track this request: it neither responds to it nor does it trigger theonUnhandledRequest
.Other http verbs seem to work fine.
I’m mentioning it here though because of @armandabric’s comment regarding versions: the issue I’m facing doesn’t happen in
v0.36.8
but it happens consistently in0.38.0
and newer versions.