Skip to content

fix: make type declarations compatible with nodenext module resolution#1983

Closed
tomquist wants to merge 1 commit into
openpgpjs:mainfrom
tomquist:fix/add-web-stream-tools-peer-dependency
Closed

fix: make type declarations compatible with nodenext module resolution#1983
tomquist wants to merge 1 commit into
openpgpjs:mainfrom
tomquist:fix/add-web-stream-tools-peer-dependency

Conversation

@tomquist

@tomquist tomquist commented Mar 9, 2026

Copy link
Copy Markdown

Summary

The published openpgp.d.ts has two issues that prevent it from working with TypeScript's --moduleResolution node16 / nodenext:

  1. TS2307: openpgp.d.ts imports types from @openpgp/web-stream-tools, but it's only a devDependency, so it's not installed for consumers. This PR adds it as an optional peerDependency.

  2. TS2834: The relative imports ./src/enums and ./src/config lack file extensions, which are required under node16/nodenext module resolution. This PR adds the .js extensions.

Changes

  • openpgp.d.ts: Add .js extensions to relative imports (./src/enums./src/enums.js, ./src/config./src/config/index.js)
  • package.json: Add @openpgp/web-stream-tools as an optional peerDependency (kept in devDependencies as well for development)

Reproduction

// tsconfig.json
{
  "compilerOptions": {
    "moduleResolution": "NodeNext",
    "module": "NodeNext"
  }
}
import { readKey } from 'openpgp';
// TS2307: Cannot find module '@openpgp/web-stream-tools'
// TS2834: Relative import paths need explicit file extensions

Partially addresses openpgpjs/web-stream-tools#10.

@tomquist tomquist force-pushed the fix/add-web-stream-tools-peer-dependency branch from 8d27cd6 to 60db48b Compare March 9, 2026 18:58
- Add file extensions to relative imports in openpgp.d.ts (TS2834)
- Add @openpgp/web-stream-tools as optional peerDependency so consumers
  using moduleResolution "node16"/"nodenext" can resolve the type import
  in openpgp.d.ts (TS2307)

The published openpgp.d.ts imports types from @openpgp/web-stream-tools,
but it was only listed as a devDependency, so it wasn't installed for
consumers. This caused TS2307 when TypeScript tried to resolve the import.

Additionally, the relative imports of ./src/enums and ./src/config lacked
file extensions, which is required under --moduleResolution node16/nodenext
(TS2834).

Fixes openpgpjs/web-stream-tools#10 (partially)
@larabr

larabr commented Mar 17, 2026

Copy link
Copy Markdown
Collaborator

Thanks for reporting and proposing a fix; closing in favor of a more general solution (#1987)

@larabr larabr closed this Mar 17, 2026
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.

2 participants