Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Console is not a constructor when compiling with jiti via graphql-codegen #2430

Open
jamespsterling opened this issue Mar 15, 2024 · 1 comment

Comments

@jamespsterling
Copy link

馃攷 Search Terms

console, _winston.default.transports.Console, is not a constructor

The problem

When compiling with graphql-codegen (via jiti), transports: defaultLogger.transports is an empty array.

export const logger = winston.createLogger({
  format: combine(
    colorize({ all: true }),
    align(),
    printf((info) => `[${info?.level}] ${info.message}`),
  ),
  transports: [new winston.transports.Console(), logtailTransport],
});
yarn run v1.22.21
$ graphql-codegen --config src/lib/index.ts

TypeError: _winston.default.transports.Console is not a constructor
    at /Users/jamessterling/Source/crm/libs/shared/logger/src/lib/logger.ts:15:16
    at evalModule (/Users/jamessterling/Source/crm/node_modules/jiti/dist/jiti.js:1:256443)
    at jiti (/Users/jamessterling/Source/crm/node_modules/jiti/dist/jiti.js:1:254371)
    at /Users/jamessterling/Source/crm/libs/shared/logger/src/index.ts:6:15
    at evalModule (/Users/jamessterling/Source/crm/node_modules/jiti/dist/jiti.js:1:256443)
    at jiti (/Users/jamessterling/Source/crm/node_modules/jiti/dist/jiti.js:1:254371)
    at /Users/jamessterling/Source/crm/libs/server/db/internal/src/lib/setupCrm.ts:16:21
    at evalModule (/Users/jamessterling/Source/crm/node_modules/jiti/dist/jiti.js:1:256443)
    at jiti (/Users/jamessterling/Source/crm/node_modules/jiti/dist/jiti.js:1:254371)
    at /Users/jamessterling/Source/crm/libs/server/db/internal/src/index.ts:30:17 {
  filepath: '/Users/jamessterling/Source/crm/libs/server/graphql/codegen/src/lib/index.ts'
}
error Command failed with exit code 1.

Adding a fallback solves my issue,

diff --git a/node_modules/winston/lib/winston.js b/node_modules/winston/lib/winston.js
index a063b2b..419b26c 100644
--- a/node_modules/winston/lib/winston.js
+++ b/node_modules/winston/lib/winston.js
@@ -171,7 +171,7 @@ Object.defineProperty(exports, 'default', {
     return {
       exceptionHandlers: defaultLogger.exceptionHandlers,
       rejectionHandlers: defaultLogger.rejectionHandlers,
-      transports: defaultLogger.transports
+      transports: defaultLogger.transports.length ? defaultLogger.transports : exports.transports
     };
   }
 });

What version of Winston presents the issue?

v3.12.0

What version of Node are you using?

v20.10.0

If this worked in a previous version of Winston, which was it?

No response

Minimum Working Example

No response

Additional information

No response

@thomaswinkler
Copy link

thomaswinkler commented Apr 22, 2024

@jamespsterling Ran into the same issue with cosmiconfig TypescriptLoader which is using jiti. As a workaround I found the following import for transports to be working with winston 3.13.0.

import transports from "winston/lib/winston/transports/";

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

No branches or pull requests

2 participants