node.jstypescriptdefinitelytyped

How to use Node.js `cluster` module with DT @types/node@16.x and TypeScript/commonjs?


I maintain a TS app using Node's cluster API that built fine with Node 14.x and Node 14.x cluster types from DT.

As I move this app to Node 16.x, I bumped @types/node from 14.x to 16.x, and then TS fails to compile:

At that point,

ā†’ What am I supposed to do? I'm asking here before filing a bug on DT, because I understand I'm possibly in a weird place because DT seems to be moving to ESM, and I'm still using TS with commonjs (my tsconfig has "module": "commonjs", "moduleResolution": "node").

... but if I try to add an "esModuleInterop": true to my tsconfig, then I get a zillion other errors from various dependencies (this is a large app).

The problem is reproducible with cluster.d.ts' example at the top of the file. Here's a TS Playground link.

ā†’ Outcomes:

  1. Am I doing something wrong? If so, why is cluster the only Node built-in module that exhibits the issue? (I'm still very much able to import * as process from 'process'; or import * as os from 'os'; for example!)
  2. Is "yup you need these ts-expect-error" the sad answer until my app is moved to ESM?
  3. Or is there something problematic with the current DT types and I should file a bug? EDIT ah, I found two DT discussions that confirm the issue: 1, 2

Solution

  • Well, this is a bug. I found two DT discussions that confirm the issue: 1, 2.

    Hadn't found them before writing this StackOverflow post because I was looking in DT Issues, but somehow they switched to Discussions.