From 9fa565a088bb8c45bb11318f7b2808d401debbf5 Mon Sep 17 00:00:00 2001 From: glifocat Date: Thu, 16 Apr 2026 13:51:43 +0200 Subject: [PATCH] fix: add .js extensions to matrix-js-sdk subpath imports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Node.js ESM requires explicit .js extensions when importing subpaths from other ESM packages that don't have matching exports map entries. The current build marks matrix-js-sdk as external in tsup.config.ts, so these import specifiers pass through verbatim to dist/index.js. matrix-js-sdk is type: "module" since v39+ and does not export the deep lib/ paths, causing ERR_MODULE_NOT_FOUND at runtime in any Node.js project that imports this adapter without a bundler. Also fixes matrix-js-sdk/lib/store → store/index.js (directory import, not a single file). Fixes #3 --- src/index.test.ts | 4 ++-- src/index.ts | 12 ++++++------ src/messages/outbound.ts | 6 +++--- src/store/chat-state-matrix-store.test.ts | 4 ++-- src/store/chat-state-matrix-store.ts | 12 ++++++------ src/types.ts | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/index.test.ts b/src/index.test.ts index cc27915..3d0a76c 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -3,8 +3,8 @@ import { Chat, getEmoji, stringifyMarkdown } from "chat"; import type { AdapterPostableMessage, ChatInstance, Logger, StateAdapter } from "chat"; import { createMemoryState } from "@chat-adapter/state-memory"; import { EventType, MsgType, RelationType, type MatrixClient } from "matrix-js-sdk"; -import { MatrixError } from "matrix-js-sdk/lib/http-api/errors"; -import { encodeRecoveryKey } from "matrix-js-sdk/lib/crypto-api/recovery-key"; +import { MatrixError } from "matrix-js-sdk/lib/http-api/errors.js"; +import { encodeRecoveryKey } from "matrix-js-sdk/lib/crypto-api/recovery-key.js"; import { createMatrixAdapter, MatrixAdapter } from "./index"; import { isMentioned } from "./messages/inbound"; import { splitOversizedTextContent } from "./messages/outbound"; diff --git a/src/index.ts b/src/index.ts index 042be70..0ce8ee1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -42,14 +42,14 @@ import sdk, { ThreadFilterType, THREAD_RELATION_TYPE, } from "matrix-js-sdk"; -import type { IStore } from "matrix-js-sdk/lib/store"; +import type { IStore } from "matrix-js-sdk/lib/store/index.js"; import type { RoomMessageEventContent, -} from "matrix-js-sdk/lib/@types/events"; -import type { MediaEventContent } from "matrix-js-sdk/lib/@types/media"; -import { MatrixError } from "matrix-js-sdk/lib/http-api/errors"; -import { decodeRecoveryKey } from "matrix-js-sdk/lib/crypto-api/recovery-key"; -import { logger as matrixSDKLogger } from "matrix-js-sdk/lib/logger"; +} from "matrix-js-sdk/lib/@types/events.js"; +import type { MediaEventContent } from "matrix-js-sdk/lib/@types/media.js"; +import { MatrixError } from "matrix-js-sdk/lib/http-api/errors.js"; +import { decodeRecoveryKey } from "matrix-js-sdk/lib/crypto-api/recovery-key.js"; +import { logger as matrixSDKLogger } from "matrix-js-sdk/lib/logger.js"; import { DEFAULT_COMMAND_PREFIX, FAST_SYNC_DEFAULTS, diff --git a/src/messages/outbound.ts b/src/messages/outbound.ts index 97241a9..c16c0d0 100644 --- a/src/messages/outbound.ts +++ b/src/messages/outbound.ts @@ -11,13 +11,13 @@ import { stringifyMarkdown, } from "chat"; import { marked } from "marked"; -import { MatrixError } from "matrix-js-sdk/lib/http-api/errors"; +import { MatrixError } from "matrix-js-sdk/lib/http-api/errors.js"; import { MsgType, RelationType } from "matrix-js-sdk"; import type { RoomMessageEventContent, RoomMessageTextEventContent, -} from "matrix-js-sdk/lib/@types/events"; -import type { MediaEventContent } from "matrix-js-sdk/lib/@types/media"; +} from "matrix-js-sdk/lib/@types/events.js"; +import type { MediaEventContent } from "matrix-js-sdk/lib/@types/media.js"; import { escapeHTML, escapeMarkdownLinkText, diff --git a/src/store/chat-state-matrix-store.test.ts b/src/store/chat-state-matrix-store.test.ts index 6c713db..e2dca6c 100644 --- a/src/store/chat-state-matrix-store.test.ts +++ b/src/store/chat-state-matrix-store.test.ts @@ -1,8 +1,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import type { Logger, StateAdapter } from "chat"; import { createMemoryState } from "@chat-adapter/state-memory"; -import type { IStateEventWithRoomId } from "matrix-js-sdk/lib/@types/search"; -import type { IndexedToDeviceBatch } from "matrix-js-sdk/lib/models/ToDeviceMessage"; +import type { IStateEventWithRoomId } from "matrix-js-sdk/lib/@types/search.js"; +import type { IndexedToDeviceBatch } from "matrix-js-sdk/lib/models/ToDeviceMessage.js"; import { ChatStateMatrixStore } from "./chat-state-matrix-store"; function makeLogger(): Logger { diff --git a/src/store/chat-state-matrix-store.ts b/src/store/chat-state-matrix-store.ts index ad9390d..7cccdde 100644 --- a/src/store/chat-state-matrix-store.ts +++ b/src/store/chat-state-matrix-store.ts @@ -1,14 +1,14 @@ import type { Logger, StateAdapter } from "chat"; import { MatrixEvent, type IStartClientOpts } from "matrix-js-sdk"; -import type { IEvent } from "matrix-js-sdk/lib/models/event"; +import type { IEvent } from "matrix-js-sdk/lib/models/event.js"; import type { IndexedToDeviceBatch, ToDeviceBatchWithTxnId, -} from "matrix-js-sdk/lib/models/ToDeviceMessage"; -import { SyncAccumulator, type ISyncResponse } from "matrix-js-sdk/lib/sync-accumulator"; -import type { IStateEventWithRoomId } from "matrix-js-sdk/lib/@types/search"; -import { MemoryStore } from "matrix-js-sdk/lib/store/memory"; -import type { ISavedSync } from "matrix-js-sdk/lib/store"; +} from "matrix-js-sdk/lib/models/ToDeviceMessage.js"; +import { SyncAccumulator, type ISyncResponse } from "matrix-js-sdk/lib/sync-accumulator.js"; +import type { IStateEventWithRoomId } from "matrix-js-sdk/lib/@types/search.js"; +import { MemoryStore } from "matrix-js-sdk/lib/store/memory.js"; +import type { ISavedSync } from "matrix-js-sdk/lib/store/index.js"; const STORE_VERSION = 1; const DEFAULT_PERSIST_INTERVAL_MS = 30_000; diff --git a/src/types.ts b/src/types.ts index 5e818a0..b890088 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,6 @@ import type { ICreateClientOpts, IStartClientOpts, MatrixClient } from "matrix-js-sdk"; import type { Logger, StateAdapter } from "chat"; -import type { IStore } from "matrix-js-sdk/lib/store"; +import type { IStore } from "matrix-js-sdk/lib/store/index.js"; export interface MatrixE2EEConfig { cryptoDatabasePrefix?: string;