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

fix: downgrade supports-color to same version as chalk #7887

Closed
wants to merge 1 commit into from

Conversation

mantoni
Copy link
Contributor

@mantoni mantoni commented Oct 31, 2024

When using the latest npm cli on node v23.1.0, all commands print this warning:

(node:36620) ExperimentalWarning: CommonJS module /opt/homebrew/lib/node_modules/npm/node_modules/debug/src/node.js is loading ES Module /opt/homebrew/lib/node_modules/npm/node_modules/supports-color/index.js using require().                                                    
Support for loading ES Module in require() is an experimental feature and might change at any time                                                                                                                                                                                   
(Use `node --trace-warnings ...` to show where the warning was created)

This happens because npm cli has a direct dependency on supports-color@v9, while chalk and debug depend on v7.x. Downgrading supports-color to v7.x fixes this. While v8.x might also work, it makes sense to depend on the same version as chalk, according to this comment in lib/utils/display.js:

get createSupportsColor from chalk directly if this lands
chalk/chalk#600

I'm not sure why so many files have automatically changed. Let me know if I'm holding it wrong.

@wraithgar
Copy link
Member

wraithgar commented Oct 31, 2024

This was fixed in nodejs/node#55085, node will no longer warn about this behavior.

This is happening because debug is making an un-manifested attempt to require('supports-color'). Un-manifested meaning that debug does not declare supports-color in dependencies or peerDependencies. They do have it listed in peerDependenciesMeta but without a complementary entry in peerDependencies it's kind of meaningless since peerDependenciesMeta only adds context to things already in peerDependencies.

This has nothing to do with chalk and downgrading the version doesn't really address what's happening under the hood. The good news is that in the latest versions of node 22 this warning has gone away.

There is also an issue in the debug repo tracking this

@wraithgar wraithgar closed this Oct 31, 2024
@ljharb
Copy link
Contributor

ljharb commented Oct 31, 2024

@wraithgar that's incorrect - that node PR is what caused the warning (in node 23), by not requiring the flag to allow requiring of ESM.

@mantoni mantoni deleted the downgrade-supports-color branch October 31, 2024 18:18
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

Successfully merging this pull request may close these issues.

3 participants