lazywithclass/winston-cloudwatch

TypeError: winston_cloudwatch_1.default is not a constructor

Closed this issue · 9 comments

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)

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'
        }),
    ]
});

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.

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

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

I am having the same issue.

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 commented

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?

Hi @lazywithclass , still I am facing this error.

(node:17287) UnhandledPromiseRejectionWarning: TypeError: winston_cloudwatch_1.default is not a constructor

tsconfig.json
image

main.ts
image

package.json
image

Please let me know if anything I am missing.

Thanks
Pramod Tolani

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

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