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

Circular reference warnings in the main library export #1886

Closed
1 of 2 tasks
alexp1917 opened this issue Feb 10, 2021 · 10 comments
Closed
1 of 2 tasks

Circular reference warnings in the main library export #1886

alexp1917 opened this issue Feb 10, 2021 · 10 comments

Comments

@alexp1917
Copy link

Please tell us about your environment:

  • winston version?
    • winston@2
    • winston@3
  • node -v outputs: v15.8.0
  • Operating System? Ubuntu: Linux $HOSTNAME 5.8.0-41-generic #46~20.04.1-Ubuntu SMP Mon Jan 18 17:52:23 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
  • Language? Javascript

What is the problem?

starting up an interactive shell prints lots of warnings after requiring the winston library, and then simply typing out its name to see its exports

Example output
$ node --trace-warnings
Welcome to Node.js v15.8.0.
Type ".help" for more information.
> var winston = require('winston')
undefined
> win(node:46170) Warning: Accessing non-existent property 'Symbol(nodejs.util.inspect.custom)' of module exports inside circular dependency
    at emitCircularRequireWarning (node:internal/modules/cjs/loader:698:11)[Getter], Stream: [Getter] }, config: { cli: [Object], npm: [Object], syslog: [Object], addColors: [Function (anon...
    at Object.get (node:internal/modules/cjs/loader:712:5)
    at formatValue (node:internal/util/inspect:746:30)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at Object.inspect (node:internal/util/inspect:336:10)
(node:46170) Warning: Accessing non-existent property 'constructor' of module exports inside circular dependency
    at emitCircularRequireWarning (node:internal/modules/cjs/loader:698:11)
    at Object.getOwnPropertyDescriptor (node:internal/modules/cjs/loader:719:5)
    at getOwnPropertyDescriptor (<anonymous>)
    at getConstructorName (node:internal/util/inspect:548:24)
    at formatRaw (node:internal/util/inspect:797:23)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
(node:46170) Warning: Accessing non-existent property 'Symbol(Symbol.toStringTag)' of module exports inside circular dependency
    at emitCircularRequireWarning (node:internal/modules/cjs/loader:698:11)
    at Object.get (node:internal/modules/cjs/loader:712:5)
    at formatRaw (node:internal/util/inspect:803:18)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
(node:46170) Warning: Accessing non-existent property 'Symbol(Symbol.iterator)' of module exports inside circular dependency
    at emitCircularRequireWarning (node:internal/modules/cjs/loader:698:11)
    at Object.get (node:internal/modules/cjs/loader:712:5)
    at formatRaw (node:internal/util/inspect:827:12)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
ston  (node:46170) Warning: Accessing non-existent property 'Symbol(nodejs.util.inspect.custom)' of module exports inside circular dependency
    at emitCircularRequireWarning (node:internal/modules/cjs/loader:698:11)[Getter], Stream: [Getter] }, config: { cli: [Object], npm: [Object], syslog: [Object], addColors: [Function (anon...
    at Object.get (node:internal/modules/cjs/loader:712:5)
    at formatValue (node:internal/util/inspect:746:30)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at Object.inspect (node:internal/util/inspect:336:10)
(node:46170) Warning: Accessing non-existent property 'constructor' of module exports inside circular dependency
    at emitCircularRequireWarning (node:internal/modules/cjs/loader:698:11)
    at Object.getOwnPropertyDescriptor (node:internal/modules/cjs/loader:719:5)
    at getOwnPropertyDescriptor (<anonymous>)
    at getConstructorName (node:internal/util/inspect:548:24)
    at formatRaw (node:internal/util/inspect:797:23)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
(node:46170) Warning: Accessing non-existent property 'Symbol(Symbol.toStringTag)' of module exports inside circular dependency
    at emitCircularRequireWarning (node:internal/modules/cjs/loader:698:11)
    at Object.get (node:internal/modules/cjs/loader:712:5)
    at formatRaw (node:internal/util/inspect:803:18)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
(node:46170) Warning: Accessing non-existent property 'Symbol(Symbol.iterator)' of module exports inside circular dependency
    at emitCircularRequireWarning (node:internal/modules/cjs/loader:698:11)
    at Object.get (node:internal/modules/cjs/loader:712:5)
    at formatRaw (node:internal/util/inspect:827:12)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
ton    (node:46170) Warning: Accessing non-existent property 'Symbol(nodejs.util.inspect.custom)' of module exports inside circular dependency
    at emitCircularRequireWarning (node:internal/modules/cjs/loader:698:11)[Getter], Stream: [Getter] }, config: { cli: [Object], npm: [Object], syslog: [Object], addColors: [Function (anon...
    at Object.get (node:internal/modules/cjs/loader:712:5)
    at formatValue (node:internal/util/inspect:746:30)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at Object.inspect (node:internal/util/inspect:336:10)
(node:46170) Warning: Accessing non-existent property 'constructor' of module exports inside circular dependency
    at emitCircularRequireWarning (node:internal/modules/cjs/loader:698:11)
    at Object.getOwnPropertyDescriptor (node:internal/modules/cjs/loader:719:5)
    at getOwnPropertyDescriptor (<anonymous>)
    at getConstructorName (node:internal/util/inspect:548:24)
    at formatRaw (node:internal/util/inspect:797:23)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
(node:46170) Warning: Accessing non-existent property 'Symbol(Symbol.toStringTag)' of module exports inside circular dependency
    at emitCircularRequireWarning (node:internal/modules/cjs/loader:698:11)
    at Object.get (node:internal/modules/cjs/loader:712:5)
    at formatRaw (node:internal/util/inspect:803:18)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
(node:46170) Warning: Accessing non-existent property 'Symbol(Symbol.iterator)' of module exports inside circular dependency
    at emitCircularRequireWarning (node:internal/modules/cjs/loader:698:11)
    at Object.get (node:internal/modules/cjs/loader:712:5)
    at formatRaw (node:internal/util/inspect:827:12)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
on      (node:46170) Warning: Accessing non-existent property 'Symbol(nodejs.util.inspect.custom)' of module exports inside circular dependency
    at emitCircularRequireWarning (node:internal/modules/cjs/loader:698:11)[Getter], Stream: [Getter] }, config: { cli: [Object], npm: [Object], syslog: [Object], addColors: [Function (anon...
    at Object.get (node:internal/modules/cjs/loader:712:5)
    at formatValue (node:internal/util/inspect:746:30)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at Object.inspect (node:internal/util/inspect:336:10)
(node:46170) Warning: Accessing non-existent property 'constructor' of module exports inside circular dependency
    at emitCircularRequireWarning (node:internal/modules/cjs/loader:698:11)
    at Object.getOwnPropertyDescriptor (node:internal/modules/cjs/loader:719:5)
    at getOwnPropertyDescriptor (<anonymous>)
    at getConstructorName (node:internal/util/inspect:548:24)
    at formatRaw (node:internal/util/inspect:797:23)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
(node:46170) Warning: Accessing non-existent property 'Symbol(Symbol.toStringTag)' of module exports inside circular dependency
    at emitCircularRequireWarning (node:internal/modules/cjs/loader:698:11)
    at Object.get (node:internal/modules/cjs/loader:712:5)
    at formatRaw (node:internal/util/inspect:803:18)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
(node:46170) Warning: Accessing non-existent property 'Symbol(Symbol.iterator)' of module exports inside circular dependency
    at emitCircularRequireWarning (node:internal/modules/cjs/loader:698:11)
    at Object.get (node:internal/modules/cjs/loader:712:5)
    at formatRaw (node:internal/util/inspect:827:12)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
n        (node:46170) Warning: Accessing non-existent property 'Symbol(nodejs.util.inspect.custom)' of module exports inside circular dependency
    at emitCircularRequireWarning (node:internal/modules/cjs/loader:698:11)[Getter], Stream: [Getter] }, config: { cli: [Object], npm: [Object], syslog: [Object], addColors: [Function (anon...
    at Object.get (node:internal/modules/cjs/loader:712:5)
    at formatValue (node:internal/util/inspect:746:30)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at Object.inspect (node:internal/util/inspect:336:10)
(node:46170) Warning: Accessing non-existent property 'constructor' of module exports inside circular dependency
    at emitCircularRequireWarning (node:internal/modules/cjs/loader:698:11)
    at Object.getOwnPropertyDescriptor (node:internal/modules/cjs/loader:719:5)
    at getOwnPropertyDescriptor (<anonymous>)
    at getConstructorName (node:internal/util/inspect:548:24)
    at formatRaw (node:internal/util/inspect:797:23)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
(node:46170) Warning: Accessing non-existent property 'Symbol(Symbol.toStringTag)' of module exports inside circular dependency
    at emitCircularRequireWarning (node:internal/modules/cjs/loader:698:11)
    at Object.get (node:internal/modules/cjs/loader:712:5)
    at formatRaw (node:internal/util/inspect:803:18)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
(node:46170) Warning: Accessing non-existent property 'Symbol(Symbol.iterator)' of module exports inside circular dependency
    at emitCircularRequireWarning (node:internal/modules/cjs/loader:698:11)
    at Object.get (node:internal/modules/cjs/loader:712:5)
    at formatRaw (node:internal/util/inspect:827:12)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
    at formatValue (node:internal/util/inspect:787:10)
    at formatProperty (node:internal/util/inspect:1675:11)
    at formatRaw (node:internal/util/inspect:1000:9)
.v  at formersion
'3.3.3'

What do you expect to happen instead?

I expect the output to not contain warnings, like so:

$ node
Welcome to Node.js v15.8.0.
Type ".help" for more information.
> var lodash = require('lodash')
undefined
> lodash
<ref *1> [Function: lodash] {
  templateSettings: {
    escape: /<%-([\s\S]+?)%>/g,
    evaluate: /<%([\s\S]+?)%>/g,
    interpolate: /<%=([\s\S]+?)%>/g,
    variable: '',
    imports: { _: [Circular *1] }
  },
  after: [Function: after],
  ary: [Function: ary],
  assign: [Function (anonymous)],
  assignIn: [Function (anonymous)],
  assignInWith: [Function (anonymous)],
  assignWith: [Function (anonymous)],
  at: [Function (anonymous)],

instead this is the output:

$ node
Welcome to Node.js v15.8.0.
Type ".help" for more information.
> var winston = require('winston')
undefined
> win(node:46398) Warning: Accessing non-existent property 'Symbol(nodejs.util.inspect.custom)' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)tp: [Getter], Stream: [Getter] }, config: { cli: [Object], npm: [Object], syslog: [Object], addColors: [Function (anon...
(node:46398) Warning: Accessing non-existent property 'constructor' of module exports inside circular dependency
(node:46398) Warning: Accessing non-existent property 'Symbol(Symbol.toStringTag)' of module exports inside circular dependency
(node:46398) Warning: Accessing non-existent property 'Symbol(Symbol.iterator)' of module exports inside circular dependency
@td-krzysiek
Copy link
Contributor

Confirmed with node v14.17.6

@rambo-panda
Copy link

Confirmed with node v20.10.0

@DABH
Copy link
Contributor

DABH commented Jan 30, 2024

If anyone wants to help figure out where this is coming from, PR would be gladly welcomed (maintainers are stretched thin). I'm happy to review any potential fix though.

@Mr0grog
Copy link

Mr0grog commented Jan 30, 2024

Took a look at things here this morning and the circular reference causing the problem is actually in winston-transport, where TransportStream (the export of the main module there) has a .LegacyTransportStream property that is a subclass of TransportStream.

It should probably be fixed there, although it can be worked around here by requiring winston-transport before any other part of the package requires winston-transport/legacy (due to an interesting quirk of how this particular circular dependency works, the problems cleans itself up automatically if you require the main export of the winston-transport module first).

Also worth noting: this issue is also currently breaking the winston.Transport.LegacyTransportStream object:

// Broken:
const winston = require('winston');
new winston.Transport.LegacyTransportStream({ transport: { log(info, cb) { cb(); }, on() {} }});
// Logs:
// new winston.Transport.LegacyTransportStream({ transport: { log(info, cb) { cb(); }, on() {} }});
// ^
//
// TypeError: winston.Transport.LegacyTransportStream is not a constructor
//     at Object.<anonymous> (/Users/rbrackett/Dev/winston/testme.js:2:1)
//     at Module._compile (node:internal/modules/cjs/loader:1241:14)
//     at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
//     at Module.load (node:internal/modules/cjs/loader:1091:32)
//     at Module._load (node:internal/modules/cjs/loader:938:12)
//     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
//     at node:internal/main/run_main_module:23:47

// But this works fine when referencing legacy transport directly:
const LegacyTransportStream = require('winston-transport/legacy');
new LegacyTransportStream({ transport: { log(info, cb) { cb(); }, on() {} }});

Mr0grog added a commit to Mr0grog/winston-transport that referenced this issue Jan 30, 2024
There is a circular dependency between the `TransportStream` (formerly in `index.js`) and `LegacyTransportStream` (in `legacy.js`). This causes some funky problems when you import the legacy module and later import the main module, as seen in winstonjs/winston#1886. I've resolved the circular issue here by definiting the main implementation of `TransportStream` in a separate module (which `LegacyTransportStream` now depends on) and then doing the work of decorating it with a `.LegacyTransportStream` property in `index.js` (and that's pretty much all the index module does).
@Mr0grog
Copy link

Mr0grog commented Jan 30, 2024

Filed a PR to fix it upstream in winston-transport: winstonjs/winston-transport#207

Once that’s merged and released, then this package will need to update its dependency on winston-transport to whatever the new version number there is.

DABH pushed a commit to winstonjs/winston-transport that referenced this issue Feb 4, 2024
* Fix circular dependency between transport streams

There is a circular dependency between the `TransportStream` (formerly in `index.js`) and `LegacyTransportStream` (in `legacy.js`). This causes some funky problems when you import the legacy module and later import the main module, as seen in winstonjs/winston#1886. I've resolved the circular issue here by definiting the main implementation of `TransportStream` in a separate module (which `LegacyTransportStream` now depends on) and then doing the work of decorating it with a `.LegacyTransportStream` property in `index.js` (and that's pretty much all the index module does).

* Resolve lint warning while I'm here
@DABH
Copy link
Contributor

DABH commented Feb 4, 2024

Thanks @Mr0grog for the help on this one! I merged the winston-transport PR and did a release there, so a fix for this should go out in the next winston release.

@Mr0grog
Copy link

Mr0grog commented Feb 4, 2024

No problem! Do I need to do a PR to update the minimum version of winston-transport in package.json here, or are you already on that/not worried about it?

@DABH
Copy link
Contributor

DABH commented Feb 4, 2024

Dependabot should automatically open a PR tomorrow but if you want to beat the bot to it, go for it :)

@Mr0grog
Copy link

Mr0grog commented Feb 4, 2024

Oh, if it's configured to update the minimums, then I'll just leave it to Dependabot. Nothing more to do here. 👍

@Mr0grog
Copy link

Mr0grog commented Mar 4, 2024

Looks like the relevant update happened in #2422 and was released in v3.12.0. I set up a project to test it out and this seems to be fixed, so I think the issue can be closed, @DABH (or whoever has permissions)!

@DABH DABH closed this as completed Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants