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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: winston_cloudwatch_1.default is not a constructor #104

Closed
jucksearm opened this issue Apr 19, 2019 · 9 comments · Fixed by #202
Closed

TypeError: winston_cloudwatch_1.default is not a constructor #104

jucksearm opened this issue Apr 19, 2019 · 9 comments · Fixed by #202
Labels

Comments

@jucksearm
Copy link

use code in typescript
import * as winston from 'winston'
import WinstonCloudWatch from 'winston-cloudwatch'
export default winston.add(new WinstonCloudWatch({}))

after run tsc
TypeError: winston_cloudwatch_1.default is not a constructor
at Object. (D:\node-project\ais-cdg-gateway\build\utils\logger.js:5:31)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)

@parque-docs
Copy link

parque-docs commented May 20, 2019

Fixed in this way:

import { createLogger, format } from 'winston';
import * as WinstonCloudWatch from 'winston-cloudwatch';

export const log = createLogger({
    level: 'debug',
    format: format.json(),
    transports: [
        new WinstonCloudWatch({
            level: 'error',
            logGroupName: 'groupName',
            logStreamName: 'errors',
            awsRegion: 'eu-west-3'
        }),
    ]
});

@perbergland
Copy link

Hmmm do you really get that to compile? For me that results in Cannot use 'new' with an expression whose type lacks a call or construct signature. for the new WinstonCloudWatch call. The typescript definition for the main class seems pretty broken, sadly.

@perbergland
Copy link

This compiles but crashes because the typescript export doesn’t match the actual export:

   transports.push(new WinstonCloudWatch.default(cwOptions));

@FrederikPriede
Copy link

I am having the same issue.

@skam22
Copy link

skam22 commented Apr 20, 2021

for anyone else having this problem I found that this fixed it fro me:

instead of

import * as WinstonCloudWatch from 'winston-cloudwatch'

use require

const WinstonCloudWatch = require('winston-cloudwatch')

@dwilt
Copy link
Contributor

dwilt commented Aug 16, 2022

In an ES6 node project and @parque-docs's solution is what only worked for me. Any reason why the docs shouldn't be updated?

@sb-pramod92

This comment was marked as resolved.

@lazywithclass
Copy link
Owner

@dwilt No, other than that's an error :D, I've just updated it. Thanks.

@tom10271
Copy link

tom10271 commented Mar 15, 2024

I am still getting WinstonCloudWatch is not a constructor with import * as WinstonCloudWatch from 'winston-cloudwatch';

Solved by calling new WinstonCloudWatch.default but not new WinstonCloudWatch

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