Skip to content

nock.back fails with TypeError: unusable when using fetch POST with a body and NOCK_BACK_MODE=update #2841

@marcello3d

Description

@marcello3d

Please avoid duplicates

Reproducible test case

example below

Nock Version

14.0.1

Node Version

20.18.1

TypeScript Version

No response

What happened?

repro

  1. Save this to script.js:
const { back: nockBack } = require("nock");
const path = require("path");

(async () => {
  nockBack.fixtures = "tests/fixtures";
  const { nockDone } = await nockBack(`good_request.json`);
  await fetch("https://api.descript.com", { method: "POST", body: "" });
  nockDone();
})();
  1. install nock: npm install [email protected]

  2. and run NOCK_BACK_MODE=update node script.js:

% NOCK_BACK_MODE=update node script.js
node:internal/deps/undici/undici:9856
          throw new TypeError("unusable");
                ^

TypeError: unusable
    at Request.clone (node:internal/deps/undici/undici:9856:17)
    at recordResponse (/Users/marcello/github/nock-back-bug/node_modules/nock/lib/recorder.js:260:32)
    at _Emitter.<anonymous> (/Users/marcello/github/nock-back-bug/node_modules/nock/lib/recorder.js:255:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async emitAsync (/Users/marcello/github/nock-back-bug/node_modules/@mswjs/interceptors/lib/node/chunk-6L3PFBGT.js:68:5)
    at async /Users/marcello/github/nock-back-bug/node_modules/@mswjs/interceptors/lib/node/chunk-LEA3MUU3.js:277:11
    at async /Users/marcello/github/nock-back-bug/script.js:7:3

Node.js v20.18.1

Note: this does not repro on 14.0.0

Would you be interested in contributing a fix?

  • yes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions