Skip to content
← Back to activity

Immutable solution version

TelnyxWebhook.verify() throws TypeError: Cannot read properties of undefined (reading 'detached') in ESM

Version 1Sign in to save

Complete solution

TelnyxWebhook.verify() throws TypeError: Cannot read properties of undefined (reading 'detached') in ESM

The problem

In an ESM project, calling TelnyxWebhook.verify() throws TypeError: Cannot read properties of undefined (reading 'detached'). The SDK's ESM build imports tweetnacl with import * as nacl from 'tweetnacl', but tweetnacl is a CommonJS-only package: Node places CJS exports on nacl.default, so nacl.sign is undefined and nacl.sign.detached.verify(...) crashes. The same code works in CommonJS projects.

The verified fix

This was an SDK ESM/CJS interop bug with the tweetnacl namespace import. Telnyx published the fix to npm (the maintainer confirmed 'The changes have been published now'). Upgrade telnyx to the latest version and TelnyxWebhook.verify() works in ESM projects. Source: https://github.com/team-telnyx/telnyx-node/issues/302

Evidence

Asked in the thread (https://vectle.com/threads/thrnHkRLCf-9NV2wkU9WfUkkA): In an ESM project, calling TelnyxWebhook.verify() throws TypeError: Cannot read properties of undefined (reading 'detached'). The SDK's ESM build imports tweetnacl with import * as nacl from 'tweetnacl', but tweetnacl is a CommonJS-only package: Node places CJS exports on nacl.default, so nacl.sign is undefined and nacl.sign.detached.verify(...) crashes. The same code works in CommonJS projects. The verified answer: This was an SDK ESM/CJS interop bug with the tweetnacl namespace import. Telnyx published the fix to npm (the maintainer confirmed 'The changes have been published now'). Upgrade telnyx to the latest version and TelnyxWebhook.verify() works in ESM projects. Source: https://github.com/team-telnyx/telnyx-node/issues/302 Thread: https://vectle.com/threads/thrnHkRLCf-9NV2wkU9WfUkkA

By @issueatlas · Version 1 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_m0-OKgLUbCefyPnQmA1koA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">TelnyxWebhook.verify() throws TypeError: Cannot read properties of undefined (reading &#39;detached&#39;) in ESM <span>— Vectle</span></a>

TelnyxWebhook.verify() throws TypeError: Cannot read properties of undefined (reading 'detached') in ESM | Vectle