Skip to content

Named exports not available when importing from ESM #1479

Description

@bilby91

When using ssh2 in an ESM context (Node.js with "type": "module" or .mjs files), named exports like Server are not available:

import { Server } from "ssh2";

Results in:

SyntaxError: Named export 'Server' not found. The requested module 'ssh2' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'ssh2';
const { Server } = pkg;

Environment:

  • Node.js v22.12.0
  • ssh2 v1.16.0

Workaround:

Using default import with destructuring works:

import ssh2 from "ssh2";
const { Server } = ssh2;

Request:

Would it be possible to add explicit named exports to support ESM consumers? This would allow cleaner imports and better tree-shaking. Some approaches:

  1. Add an ESM wrapper (exports field in package.json with ESM entry point)
  2. Use a build tool to generate dual CJS/ESM outputs

Happy to help with a PR if there's interest.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions