nbd-wtf / nostr-tools

Tools for developing Nostr clients.
The Unlicense
695 stars 193 forks source link

Build fails on import statement after v1.10.0 "nostr-tools has no exported member" #255

Closed steliosrammos closed 11 months ago

steliosrammos commented 1 year ago

Upgrading to v1.11 or higher results in a build time error when importing from nostr-tools.

Example:

import { SimplePool } from "nostr-tools";

Results in:

 error TS2305: Module '"nostr-tools"' has no exported member 'SimplePool'

The same happens with other imports from nostr-tools too.

Possibly related to: https://github.com/nbd-wtf/nostr-tools/commit/9f896479d0758886278af91f82afe649bce4401f

rolznz commented 1 year ago

@steliosrammos it failed for me too building alby-js-sdk. What typescript version are you using? updating to the lastest (^5.1.6) now compiles.

Note: for me most versions worked fine (nostr-tools v1.10.0 - 1.13.0 built successfully but 1.13.1 failed)

https://github.com/nbd-wtf/nostr-tools/compare/v1.13.0...v1.13.1 is only dependency changes, so I am not sure why it started happening here.

fiatjaf commented 1 year ago

Everybody should stop using JavaScript.

wbobeirne commented 1 year ago

I've poked around at the .d.ts files that the published package has, and noticed two issues.

  1. Imports are specifying the.ts extension on import (e.g. export * from './relay.ts')
    • Looks like this was added in #213, however allowImportingTsExtensions seems to note that it now requires your bundler to know how to deal with these imports, so I suspect this is more problematic than initially expected
  2. Type imports are using a syntax I've never seen before:
    import { Something, type SomethingElse } from '...'

    Which is not something I could find any documentation around. However I'm familiar with

    import type { Something, SomethingElse } from '...`

    which you can only use if all imports are type-only.

I'd be happy to put up a PR with some fixes to these, but would also ask @alexgleason to weigh in and make sure it doesn't break anything for Deno users to revert the allowImportingTsExtensions change.

monlovesmango commented 12 months ago

@steliosrammos were you able to get this resolved? I am running into this as well, but only for the typescript files in my project (javascript files import fine) and only for direct exports like matchFilter or simplePool (all the nipXX import fine still)

wbobeirne commented 11 months ago

@monlovesmango you just need to update to latest typescript, that should fix it.

monlovesmango commented 11 months ago

thanks @wbobeirne! that did it