Skip to content

build: Publish NPM package with type commonjs #2047

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

Merged
merged 1 commit into from
Apr 27, 2025

Conversation

Danielku15
Copy link
Member

Issues

Fixes #2045 #2044

Proposed changes

Node.js seems to have a bit a wierd behavior when it comes to loading modules. Despite the exports section defining (seemingly) the format and path for it, it behaves different.

Likely this started to become a problem with Node 22 which added support to load ESM files from CommonJS files:

The conditional export is only used to resolve the path to the file. But then if .js is used as extension, they load the file based on type in the parent package.json.

We have type: module as we mainly use ESM stuff in our own repo and a lot of tooling, and also node itself when executing scripts, rely on this. Again some tooling do not support extensions like .mts.

Using .cjs is also not fully correct as alphaTab itself is rather a UMD than a CJS only. The extension change would be a breaking one and could lead to problems when using this file in browser scenarios.

Putting this all together, our best choice is to rewrite the package.json before packing/publishing the NPM to mark publicly that .js files in this package are commonjs, but keeping things as ESM when working on this project.

Checklist

  • I consent that this change becomes part of alphaTab under it's current or any future open source license
  • Changes are implemented
  • New tests were added

Further details

  • This is a breaking change
  • This change will require update of the documentation/website

@Danielku15 Danielku15 self-assigned this Apr 27, 2025
@Danielku15 Danielku15 force-pushed the feature/type-module branch from 60e7534 to 13aeab3 Compare April 27, 2025 20:49
@Danielku15 Danielku15 merged commit dd60935 into develop Apr 27, 2025
5 checks passed
@Danielku15 Danielku15 deleted the feature/type-module branch April 27, 2025 20:52
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.

Angular Webpack Example Broken in 19
1 participant