lazywithclass/winston-cloudwatch

TypeScript import issue

Closed this issue · 7 comments

I'm getting the following TypeScript error when using this library:

Cannot use 'new' with an expression whose type lacks a call or construct signature.'
source: 'ts'

import * as winston from 'winston';
import * as WinstonCloudWatch from 'winston-cloudwatch';

let logger = new winston.Logger({
    transports: [
        new WinstonCloudWatch({
            level: process.env.LOG_LEVEL,
            timestamp: true,
            awsRegion: 'us-east-1',
            logGroupName: process.env.AWS_LOGS_GROUP,
            logStreamName: process.env.ENV
        })
    ]
});

I'm not familiar with TypeScript, the support has been added as a PR, but I will surely have a look into it; any pointers / hints would be greatly appreciated!

I'm pretty new to it as well. This was the only library where I had an issue like this so I thought I would create an issue.

@stevenmusumeche How can I replicate this? Could you please provide a minimum setup?

I am not sure if it's just a matter of creating a .ts file with that code at the root of the project.

I believe if you create a server.ts file in the root of the project and put the code above you will see the same error from TypeScript.

@stevenmusumeche I've some errors doing what you suggested so I created a new repo, this way I can clearly see what's the minimum required configuration and point future users with the same problem to it.

What's the command I should use to see the error? tsc server.ts gives a lot of errors like

node_modules/aws-sdk/clients/dynamodb.d.ts(309,38): error TS2304: Cannot find name 'Buffer'.
node_modules/aws-sdk/clients/dynamodbstreams.d.ts(92,38): error TS2304: Cannot find name 'Buffer'.
node_modules/aws-sdk/clients/ec2.d.ts(2667,23): error TS2304: Cannot find name 'Buffer'.
node_modules/aws-sdk/clients/ecr.d.ts(612,31): error TS2304: Cannot find name 'Buffer'.
node_modules/aws-sdk/clients/firehose.d.ts(144,22): error TS2304: Cannot find name 'Buffer'.
node_modules/aws-sdk/clients/glacier.d.ts(1116,24): error TS2304: Cannot find name 'Buffer'.

...but in the end it creates the .js file. Any help would be greatly appreciated.

That is the command, but those errors are probably related to not having the typings installed for winston. npm install @types/winston should fix that.

However, I redid my setup to use npm scripts instead of gulp, and it appears I am no longer getting this error, so it may have been my error all along.

I do apologize for raising an unnecessary issue and wasting your time.

Ah no worries for that :)

I appreciate you coming back here and telling me so!