Named exports not available when importing from ESM
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 5.8k
- Forks
- 734
- PR merge metrics
- No merged PRs in 30d
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by inspecting package.json and the current CommonJS package entry point, then reproduce the named-import failure in Node.js with an ESM file. Compare the proposed ESM wrapper and dual-output approaches, and define done as making imports such as Server available to ESM consumers while preserving the existing CommonJS workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100