Fix CBOR decoder "keyDecoder is undefined" error with runtime patch#928
Draft
Fix CBOR decoder "keyDecoder is undefined" error with runtime patch#928
Conversation
- Add runtime patch for sharedCachedUtf8Decoder export issue - Fix CLI json-unpack tool to use patched CBOR decoder - Add comprehensive regression tests for the fix - Patch automatically applies when importing CBOR utilities Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] json-pack: sharedCachedUtf8Decoder_1.default is undefined because tslib exportStar skips export named default
Fix CBOR decoder "keyDecoder is undefined" error with runtime patch
Aug 7, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR fixes a critical runtime error where CBOR decoders fail with "Cannot read properties of undefined (reading 'decode')" due to a missing
keyDecoderproperty.Problem
Users encounter this error when using CBOR functionality:
The issue occurs because
this.keyDecoderisundefinedin theCborDecoderBaseconstructor.Root Cause
The problem stems from a re-export issue in the
@jsonjoy.com/utilpackage. The file@jsonjoy.com/util/lib/buffers/utf8/sharedCachedUtf8Decoder.jsuses:However,
tslib.__exportStarintentionally skips thedefaultexport. Since the original module exports the shared UTF8 decoder asdefault, it gets lost during re-export, makingsharedCachedUtf8Decoder_1.defaultundefined.Solution
This PR implements a runtime patch that:
defaultexport is missing from the re-exported module@jsonjoy.com/bufferspackagedefaultexportUsage
The fix works automatically - no code changes required:
CLI tools also work correctly:
Testing
Added comprehensive regression tests that verify:
Backward Compatibility
The fix is completely backward compatible and requires no changes to existing code. The patch only activates when the problematic re-export is detected.
Fixes #925.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.