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

[Bug]: TS2339: Property 'metadata' does not exist on type 'TransformableInfo'. #2286

Open
DaCao opened this issue Mar 1, 2023 · 3 comments

Comments

@DaCao
Copy link

DaCao commented Mar 1, 2023

🔎 Search Terms

TS2339, metadata, does not exist, TransformableInfo,

The problem

The below code works perfectly fine in one project:

const format_string_console = combine(
  format.errors({ stack: true }),
  timestamp({ format: timezonedTime }),
  format.ms(),
  format.metadata(),
  format.colorize({ all: true }),
  winston.format.printf(
    info =>
      `${info.metadata.timestamp} ${info.metadata.ms} ${info.metadata.host} pid:${process.pid} ` +
      `${info.level}: ${info.message}`,
  ),
);

However, when running the same code in another project, it gives this error:

ubuntu@ip-172-31-43-104:~/myapp/worker$ nodemon --exec ts-node --files src/index.ts
[nodemon] 2.0.20
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: ts,json
[nodemon] starting `ts-node --files src/index.ts`
/home/ubuntu/myapp/worker/node_modules/ts-node/src/index.ts:859
    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
src/utils/logger/devLogger.ts:48:15 - error TS2339: Property 'metadata' does not exist on type 'TransformableInfo'.

48       `${info.metadata.timestamp} ${info.metadata.ms} ${info.metadata.host} pid:${process.pid} ` +
                 ~~~~~~~~
src/utils/logger/devLogger.ts:48:42 - error TS2339: Property 'metadata' does not exist on type 'TransformableInfo'.

48       `${info.metadata.timestamp} ${info.metadata.ms} ${info.metadata.host} pid:${process.pid} ` +
                                            ~~~~~~~~
src/utils/logger/devLogger.ts:48:62 - error TS2339: Property 'metadata' does not exist on type 'TransformableInfo'.

48       `${info.metadata.timestamp} ${info.metadata.ms} ${info.metadata.host} pid:${process.pid} ` +
                                                                ~~~~~~~~
src/utils/logger/devLogger.ts:60:15 - error TS2339: Property 'metadata' does not exist on type 'TransformableInfo'.

60       `${info.metadata.timestamp} ${info.metadata.ms} ${info.metadata.host} pid:${process.pid} ` +
                 ~~~~~~~~
src/utils/logger/devLogger.ts:60:42 - error TS2339: Property 'metadata' does not exist on type 'TransformableInfo'.

60       `${info.metadata.timestamp} ${info.metadata.ms} ${info.metadata.host} pid:${process.pid} ` +
                                            ~~~~~~~~
src/utils/logger/devLogger.ts:60:62 - error TS2339: Property 'metadata' does not exist on type 'TransformableInfo'.

60       `${info.metadata.timestamp} ${info.metadata.ms} ${info.metadata.host} pid:${process.pid} ` +
                                                                ~~~~~~~~
src/utils/logger/devLogger.ts:74:15 - error TS2339: Property 'metadata' does not exist on type 'TransformableInfo'.

74       `${info.metadata.timestamp} ${info.metadata.ms} ${info.metadata.host} pid:${process.pid} ` +
                 ~~~~~~~~
src/utils/logger/devLogger.ts:74:42 - error TS2339: Property 'metadata' does not exist on type 'TransformableInfo'.

74       `${info.metadata.timestamp} ${info.metadata.ms} ${info.metadata.host} pid:${process.pid} ` +
                                            ~~~~~~~~
src/utils/logger/devLogger.ts:74:62 - error TS2339: Property 'metadata' does not exist on type 'TransformableInfo'.

74       `${info.metadata.timestamp} ${info.metadata.ms} ${info.metadata.host} pid:${process.pid} ` +
                                                                ~~~~~~~~
src/utils/logger/devLogger.ts:87:22 - error TS2339: Property 'metadata' does not exist on type 'TransformableInfo'.

87       return `${info.metadata.timestamp} ${moment(parseFloat(info.metadata.timestamp))} `;
                        ~~~~~~~~
src/utils/logger/devLogger.ts:87:67 - error TS2339: Property 'metadata' does not exist on type 'TransformableInfo'.

87       return `${info.metadata.timestamp} ${moment(parseFloat(info.metadata.timestamp))} `;
                                                                     ~~~~~~~~

    at createTSError (/home/ubuntu/myapp/worker/node_modules/ts-node/src/index.ts:859:12)
    at reportTSError (/home/ubuntu/myapp/worker/node_modules/ts-node/src/index.ts:863:19)
    at getOutput (/home/ubuntu/myapp/worker/node_modules/ts-node/src/index.ts:1077:36)
    at Object.compile (/home/ubuntu/myapp/worker/node_modules/ts-node/src/index.ts:1433:41)
    at Module.m._compile (/home/ubuntu/myapp/worker/node_modules/ts-node/src/index.ts:1617:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Object.require.extensions.<computed> [as .ts] (/home/ubuntu/myapp/worker/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:94:18)
    at Object.<anonymous> (/home/ubuntu/myapp/worker/src/utils/logger/index.ts:1:1)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Module.m._compile (/home/ubuntu/myapp/worker/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Object.require.extensions.<computed> [as .ts] (/home/ubuntu/myapp/worker/node_modules/ts-node/src/index.ts:1621:12) {
  diagnosticCodes: [
    2339, 2339, 2339,
    2339, 2339, 2339,
    2339, 2339, 2339,
    2339, 2339
  ]
}
[nodemon] app crashed - waiting for file changes before starting...

What is this?

There is no information about this error on the internet.

Both projects are using node version v16.6.1, and
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.7.1",
"ts-node": "^10.9.1",
"typescript": "^3.7.2"

Everything is the same, and yet it gives this incredible error.

I have also tried:
"winston": "^3.8.2",
"winston": "^3.7.1",
But no luck at all.

I am pulling my hair so hard. What is this bug?

What version of Winston presents the issue?

v3.3.3

What version of Node are you using?

v16.6.1

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

v3.3.3

Minimum Working Example

No response

Additional information

No response

@wbt
Copy link
Contributor

wbt commented Mar 1, 2023

Try using TS 4.4+ (as a long-term solution) or in the short-term maybe using this override to pin an older version of logform.

@DaCao
Copy link
Author

DaCao commented Mar 2, 2023

For anyone who encounters the same issue, here is how I fixed it:

make sure that the package "logform" in installed with version "^2.3.0"

npm i logform@2.3.0

I also changed the version of

-    "winston-daily-rotate-file": "^4.7.1",
+    "winston-daily-rotate-file": "^4.6.1",

but I don't think this was necessary though.

@wbt
Copy link
Contributor

wbt commented Mar 2, 2023

You'll want at least 2.3.1, since 2.3.0 was broken (oops!).
However, the TypeScript version (should be 4.4+) seems like the more important part.

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