Skip to content

endSession() throws ReferenceError: b is not defined in ESM bundle in 3.30.1 #225

@hodorsoft

Description

@hodorsoft

When using the ESM bundle of @cognigy/webchat, calling webchat.endSession() throws a ReferenceError due to what appears to be a minification/bundling issue with the self.crypto.randomUUID() reference.

Version

@cognigy/webchat/v/3.30.1

Reproduction

  1. Import the webchat using the ESM bundle
  2. Initialize the webchat
  3. Call webchat.endSession()

Expected behaviour

The session should end and a new session ID should be generated.

Actual behaviour

ReferenceError: b is not defined

The error originates from the bundled code where self.crypto.randomUUID() appears to have been incorrectly minified/tree-shaken.

Workaround

The endSession() behavior can seemingly be replicated by dispatching the underlying Redux actions directly:

webchat.store.dispatch({
  type: "SWITCH_SESSION",
  sessionId: crypto.randomUUID(),
});
webchat.store.dispatch({ type: "CLEAR_MESSAGES" });

This bypasses the broken bundled code by calling the browser's native crypto.randomUUID() directly.

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