Skip to content

fix(cli): correct node:cluster import for multiprocess mode - #2852

Closed
y-tajiri wants to merge 1 commit into
stoplightio:mainfrom
y-tajiri:fix/node-cluster-import
Closed

y-tajiri wants to merge 1 commit into
stoplightio:mainfrom
y-tajiri:fix/node-cluster-import

Conversation

@y-tajiri

@y-tajiri y-tajiri commented Sep 4, 2026

Copy link
Copy Markdown

Problem

Starting the CLI in multiprocess mode (--multiprocess / -m) crashes immediately with:

Cannot read properties of undefined (reading 'isPrimary')

packages/cli/src/util/createServer.ts imports node:cluster as a default import:

import cluster from 'node:cluster';

The project compiles to CommonJS without esModuleInterop, so this emits a .default property access. node:cluster exposes its API on the module object itself, so .default is undefined at runtime and every subsequent cluster.* access throws.

Fix

Use an import-equals require so the runtime object is the module itself, and reconcile it with @types/node (which models the API as a default export):

import clusterModule = require('node:cluster');
const cluster = (clusterModule as typeof clusterModule & { default?: typeof clusterModule }).default ?? clusterModule;

This keeps type-checking happy under the current tsconfig while working correctly at runtime.

Notes

🤖 Generated with Claude Code

Multiprocess mode crashed on startup with "Cannot read properties of undefined
(reading 'isPrimary')". The default import of node:cluster compiled to a
`.default` access, which is undefined at runtime because the project builds
CommonJS without esModuleInterop and node:cluster's API lives on the module
object itself. Use an import-equals require and reconcile the @types/node
default-export typing with the runtime shape.
@y-tajiri
y-tajiri requested a review from a team as a code owner September 4, 2026 02:29
@y-tajiri y-tajiri closed this Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants