Skip to content

Fix compatibility with current nostr-tools#1

Open
bitcoin3us wants to merge 1 commit into
codonaft:codonaftfrom
bitcoin3us:fix/nostr-tools-compat
Open

Fix compatibility with current nostr-tools#1
bitcoin3us wants to merge 1 commit into
codonaft:codonaftfrom
bitcoin3us:fix/nostr-tools-compat

Conversation

@bitcoin3us
Copy link
Copy Markdown

Problem

vite build fails against recent nostr-tools releases:

RollupError: "replaceAll" is not exported by "node_modules/nostr-tools/lib/esm/nip27.js", imported by "src/util/ui.ts".

nostr-tools removed the matchAll / replaceAll helpers from its nip27 module — current versions export only parse. A few AbstractRelay APIs that network.ts relied on have also changed. Since package.json declares nostr-tools: ^2.7.1 (which resolves to the latest 2.x), a clean npm install + vite build currently aborts.

Changes

nip27 — vendor a minimal src/util/nip27.ts that restores exactly the matchAll / replaceAll behaviour ZapThreads used: it matches NIP-21 nostr: references and decodes them via nip19. ui.ts imports from the local module instead of nostr-tools/nip27; behaviour is unchanged (decode failures are skipped / passed through rather than thrown).

network.ts — port to the current AbstractRelay API:

  • connectionTimeout is no longer a settable property — the timeout is passed per call via relay.connect({ timeout }).
  • The private _onauth hook was removed. It is dropped here; relays that require NIP-42 AUTH to read are already detected from the subscription close reason in handleClose, so behaviour is preserved.
  • PrioritizedPool's constructor is typed with AbstractRelayConstructorOptions (it only reads verifyEvent / websocketImplementation); AbstractPoolConstructorOptions now requires fields the class does not use.
  • window.nostr.getRelays() is now optional in the Nostr type — guarded.

Testing

  • Builds cleanly against nostr-tools 2.23.x — vite build produces dist/ with no errors related to these changes.
  • Verified in a browser on a live NIP-52 calendar event: relay connections, comment loading, and the comment composer all work.
  • Two pre-existing, unrelated TS warnings remain (index.tsx Section typing, remarkable/linkify missing types) — left out of scope.

Note

package.json still declares nostr-tools: ^2.7.1, but the code now targets the current relay API — you may want to bump that range. Left unchanged to keep this PR focused.

The production build fails against current nostr-tools versions, and a
couple of relay APIs the pool relied on have changed.

- nip27: nostr-tools removed the `matchAll` / `replaceAll` helpers from
  its `nip27` module (current versions export only `parse`), which broke
  the build with a fatal Rollup error ("replaceAll is not exported").
  Vendor a small `src/util/nip27.ts` that restores exactly the behaviour
  ZapThreads used — matching NIP-21 `nostr:` references and decoding them
  via nip19 — so the build no longer depends on the removed exports.

- network.ts: AbstractRelay no longer exposes the `connectionTimeout`
  property or the private `_onauth` hook. Pass the timeout via
  `relay.connect({ timeout })` instead, and drop the `_onauth` hook —
  relays that require NIP-42 AUTH to read are already detected from the
  subscription close reason in `handleClose`. Type the pool constructor
  with `AbstractRelayConstructorOptions` (it only ever reads relay
  options), and guard the now-optional `window.nostr.getRelays()`.

Builds cleanly against nostr-tools 2.23.x; the widget was verified in a
browser (relay connection, comment loading and the composer all work).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@bitcoin3us bitcoin3us force-pushed the fix/nostr-tools-compat branch from 47de571 to 9a75898 Compare May 21, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant