build: Publish NPM package with type commonjs #2047
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ontype
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
Further details