-
Notifications
You must be signed in to change notification settings - Fork 708
Open
Description
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:
- Add an ESM wrapper (
exportsfield in package.json with ESM entry point) - Use a build tool to generate dual CJS/ESM outputs
Happy to help with a PR if there's interest.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels