question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Premature close

See original GitHub issue

Prerequisites

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

https://github.com/molvqingtai/resreq/blob/35d7e2e19d3bbbca6d4c55f5fd6119db7afdc30d/__tests__/main.spec.ts

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:open
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
armandabriccommented, Mar 22, 2022

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 issue
  • v0.38.0 trigger the issue
  • v0.38.1 trigger the issue
  • v0.38.2 trigger the issue
  • v0.39.2 trigger the issue

By looking into the changelog of the v0.38.0, it could linked to the interceptor upgrade.

1reaction
lautarodragancommented, May 31, 2022

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 the onUnhandledRequest.

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 in 0.38.0 and newer versions.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found