Replace winston deep import with main-entry import for ESM#138
Merged
Conversation
`import { Console, ConsoleTransportOptions } from 'winston/lib/winston/transports'`
worked under CJS but fails from the published ESM build. Two reasons:
- It's a directory import — Node ESM requires the explicit `/index.js`
suffix and otherwise throws `ERR_UNSUPPORTED_DIR_IMPORT`.
- Even with the suffix, winston's transports index exposes `Console` via
`Object.defineProperty(exports, 'Console', { get() { return require('./console') } })`,
a shape `cjs-module-lexer` doesn't expose as an ESM named binding —
importers get `SyntaxError: Named export 'Console' not found`.
Go through winston's main entry (`exports.transports = require(...)`)
instead, which cjs-module-lexer handles cleanly. Verified the produced
`dist/index.mjs` no longer references the deep path, and that a consumer
ESM project (vitest) can now import `@makerx/node-winston` without the
SyntaxError.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
pleb
approved these changes
Apr 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a runtime
SyntaxErrorin the v2 beta ESM build when consumers import from@makerx/node-winstonunder pure ESM (e.g. Vitest, Node 22+ with"type": "module"):The offending line was:
That worked under CJS
require()but breaks in ESM for two reasons (verified against winston 3.19.0):/index.jssuffix; otherwise it throwsERR_UNSUPPORTED_DIR_IMPORT.winston/lib/winston/transports/index.jsdefinesConsoleviaObject.defineProperty(exports, 'Console', { get() { return require('./console') } }).cjs-module-lexer(what Node's ESM→CJS interop uses) doesn't expose this shape as an ESM named binding, soimport { Console }fails.Fix: go through winston's main entry, which does
exports.transports = require('./winston/transports')— a form cjs-module-lexer handles cleanly.ConsoleTransportOptionsis now sourced via thetransportsnamespace (type-only).Also updated the direct-usage example in the README to match.
Test plan
npm run check-typespassesnpm run lintpassesnpm run test— all 34 tests passnpm run build— verifieddist/index.mjsno longer referenceswinston/lib/winston/transportsSyntaxError: Named export 'Console' not foundis gone and the suite passes🤖 Generated with Claude Code