Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix derby/server cluster imports #635

Merged
merged 2 commits into from
May 16, 2024
Merged

Fix derby/server cluster imports #635

merged 2 commits into from
May 16, 2024

Conversation

craigbeck
Copy link
Contributor

@craigbeck craigbeck commented May 15, 2024

Downstream code failing when using derby/server as cluster imported in trasformed with default import like this:

// there is no cluster.default
 if (cluster.default.isPrimary) {
    console.log('Primary PID ', process.pid);
    startWorker();
  }

and erors with default is undefined

Additionally added forward compatible mapping for pre node16 module resolutions for server

@craigbeck craigbeck requested a review from ericyhwang May 16, 2024 17:48
Copy link
Contributor

@ericyhwang ericyhwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be a mismatch in types vs runtime:

  • @types/node indicates that the built-in "cluster" module is an ES module
  • We compile to CommonJS, so TS inserts the extra .default to allow usage of a (supposed) ES module's default after using a CommonJS require
  • However, because the output JS is using require, Node provides the CommonJS version of "cluster", not the ESM version

This could also be resolved by using esModuleInterop in tsconfig, but I'm reluctant to do that because of the extra helper functions inserted in each output file by TS when using that option.

@craigbeck craigbeck merged commit 6c6f397 into master May 16, 2024
5 checks passed
@craigbeck craigbeck deleted the fix-server branch May 16, 2024 19:04
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