Skip to content

TypeError: Cannot read properties of undefined (reading 'sphereon') in ES modules environment #323

@kitakaze-kan

Description

@kitakaze-kan

Hi, there seems to be a bug with mdoc.

Issue Summary

When using @sphereon/ssi-types in an ES modules environment ("type": "module"),
the decodeMdocDeviceResponse function fails with a runtime error: Cannot read
properties of undefined (reading 'sphereon').

Environment

  • @sphereon/ssi-types: 0.34.0
  • @sphereon/kmp-mdoc-core: 0.2.0-SNAPSHOT.26
  • Node.js: ES modules ("type": "module" in package.json)
  • TypeScript config: "moduleResolution": "bundler", "esModuleInterop": true

Root Cause

The issue occurs due to a module format mismatch between TypeScript declarations
and JavaScript runtime:

  1. TypeScript declarations: The .d.ts file declares export declare namespace
    com.sphereon.mdoc
  2. JavaScript runtime: The actual UMD module exports create nested objects under
    default in ES modules
  3. Import pattern: src/utils/mdoc.ts uses import * as mdoc from
    '@sphereon/kmp-mdoc-core'

In ES modules environment:

  • mdoc.com is undefined
  • mdoc.default.com.sphereon contains the actual exports

Stack Trace

  error TypeError: Cannot read properties of undefined (reading 'sphereon')
      at decodeMdocDeviceResponse
  (/node_modules/@sphereon/ssi-types/src/utils/mdoc.ts:75:35)
      at toWrappedVerifiablePresentation
  (/node_modules/@sphereon/ssi-types/src/mapper/credential-mapper.ts:163:26)

Expected Behavior

The decodeMdocDeviceResponse function should work correctly in ES modules
environments.

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions