httptoolkit / httptoolkit

HTTP Toolkit is a beautiful & open-source tool for debugging, testing and building with HTTP(S) on Windows, Linux & Mac :tada: Open an issue here to give feedback or ask for help.
https://httptoolkit.com
2.75k stars 71 forks source link

[Bug]: httptoolkit does not record requests from turbo #613

Open cbou opened 2 months ago

cbou commented 2 months ago

Has this been reported before?

Repro steps

Create a new turbo repo project:

npx create-turbo@latest

Create a new file apps/web/fetch.js with the following code:

const http = require("http");

const options = {
  hostname: "example.com",
  port: 80,
  path: "/",
  method: "GET",
};

const req = http.request(options, (res) => {
  let data = "";

  // A chunk of data has been received.
  res.on("data", (chunk) => {
    data += chunk;
  });

  // The whole response has been received.
  res.on("end", () => {
    console.log(data);
  });
});

req.on("error", (e) => {
  console.error(`Problem with request: ${e.message}`);
});

// End the request
req.end();

Add this line to the scripts of apps/web/package.json

"fetch": "node fetch.js"

Add this line to the scripts of package.json

"fetch": "turbo fetch",

Add this line to the tasks of turbo.json

    "fetch": {
      "cache": false,
      "persistent": true
    }

Now start httptoolkit and record your terminal with

eval "$(curl -sS localhost:8001/setup)"

First run fetch via turbo with npm run fetch, nothing will be log in httptoolkit. After do the same directly via node with node fetch.js, the request will be logged.

turbo 2.0.11
node v20.12.1
httptoolkit 1.14.8

How often does this bug happen?

Every time

The desktop OS you're using

Mac OS 14.6

Details of other apps/devices

No response

Error screenshot

No response

Any other info?

No response

pimterry commented 2 months ago

Hmmm, I don't know much about Turbo I'm afraid.

In this case, much of the interception is powered by env vars, which are expected to propagate into subprocesses. It seems like Turbo filters env vars by default to only the settings it recognizes (see https://turbo.build/repo/docs/crafting-your-repository/using-environment-variables#strict-mode) which sounds like it might be related! If you run Turbo with --env-mode=loose does that resolve this for you?