Skip to content

Conversation

@Tatsinnit
Copy link
Member

@Tatsinnit Tatsinnit commented Mar 18, 2025

This PR is open with intent to fix #130

This PR addresses and fixes the issue where the Kubernetes client (@kubernetes/client-node) had compatibility problems with ESM (ECMAScript Modules) and CommonJS. This PR fix resolves the syntax errors related to the use of export in CommonJS contexts and ensures smoother integration.

Additionally, it includes the necessary adjustments to configuration and module handling, improving the overall compatibility with newer module systems.

Thanks heaps, ❤️

@Tatsinnit Tatsinnit requested a review from a team as a code owner March 18, 2025 21:08
@Tatsinnit Tatsinnit self-assigned this Mar 18, 2025
@Tatsinnit Tatsinnit added enhancement Feature request/improved experience dependencies Pull requests that update a dependency file labels Mar 18, 2025
Signed-off-by: Tatsat Mishra <tamishra@microsoft.com>
@Tatsinnit Tatsinnit force-pushed the fix/client-node-update branch from f5c3cc8 to e062256 Compare March 18, 2025 21:14
@bosesuneha
Copy link
Member

Thanks for the PR, @Tatsinnit! It looks great! Could you add some notes in the description for future reference in case we need to revisit this PR for a similar issue?

@Tatsinnit Tatsinnit enabled auto-merge (squash) March 18, 2025 23:09
@Tatsinnit
Copy link
Member Author

Tatsinnit commented Mar 19, 2025

Thanks for the PR, @Tatsinnit! It looks great! Could you add some notes in the description for future reference in case we need to revisit this PR for a similar issue?

Thank you @bosesuneha , essentially there is no silver bullet for these fixes but I am about to gist the key thing and starting point how we will handle.

Information built-up:

  • Client-node has decided to only support ESM which mean the commons projects will see ESM errors.
  • Best place to see if our project is ESM or not is package.json - type: "module" - will mean it its ESM support, so in this project this was my starting point, then the mix will come, after checking all was using import next was track down errors and handle one error at a time.

For this specific case adding babel did the magic and then this: https://jestjs.io/docs/ecmascript-modules came handy.

ESM vs Commonjs

ESM:

ESM also known as (ECMAScript Modules):

  • Static Structure: Imports and exports are static. This means they are determined at compile time, which allows for better static analysis and tree-shaking (removing unused code during bundling).
  • Standardized: ESM is part of the official ECMAScript standard and is now natively supported by modern browsers and Node.js (with some configuration).
  • Asynchronous Loading: ESM supports asynchronous module loading, which can be beneficial for performance in certain scenarios (especially in browser environments).
CommonJS
  • Dynamic Structure: CommonJS modules are loaded at runtime, which allows for dynamic imports (e.g., conditional or computed module paths). However, this dynamism makes static analysis and tree-shaking more challenging.
  • Traditional in Node.js: CommonJS has been the de facto module system for Node.js for many years, and many packages in the Node ecosystem still use it.

I am sure there is more but hope this gives some insight as to how I thought this could be solved until it was all good and green.

Thanks.

Copy link

@ReinierCC ReinierCC left a comment

Choose a reason for hiding this comment

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

Great solution! and thanks for the explaination!

@Tatsinnit Tatsinnit merged commit 959bbfb into Azure:main Mar 19, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file enhancement Feature request/improved experience

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants