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

Module not found: Error: debug tried to access supports-color (a peer dependency) but it isn't provided by its ancestors #18

Open
irudoy opened this issue Aug 15, 2020 · 3 comments

Comments

@irudoy
Copy link

irudoy commented Aug 15, 2020

Got those errors during webpack build, using yarn@berry:

    Module not found: Error: debug tried to access supports-color (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.

    Required package: supports-color (via "supports-color")
    Required by: debug@virtual:ef2fb28f3185f9ba345cf0214d372bc8e04344320dd80b839f12ab23fbe300f7c2a62784bfffb92cb431640b461f8eb544464aadcc1823ebefc40d17e8ec16c9#npm:4.1.1 (via /.../.yarn/$$virtual/debug-virtual-be097de51f/0/cache/debug-npm-4.1.1-540248b3aa-3.zip/node_modules/debug/src/node.js)

     @ ./.yarn/$$virtual/debug-virtual-be097de51f/0/cache/debug-npm-4.1.1-540248b3aa-3.zip/node_modules/debug/src/node.js
     @ ./.yarn/$$virtual/debug-virtual-be097de51f/0/cache/debug-npm-4.1.1-540248b3aa-3.zip/node_modules/debug/src/index.js
     @ ./.yarn/cache/esx-npm-2.3.3-0851126841-3.zip/node_modules/esx/index.js
@giorgio-zamparelli
Copy link

giorgio-zamparelli commented Jun 13, 2021

I solved this by adding an entry packageExtensions to the yarn config file .yarnrc.yml

packageExtensions:
  debug@*:
    dependencies:
      supports-color: "*"

Run yarn after changing the .yarnrc.yml file.

You can find more info on the .yarnrc.yml file here: https://yarnpkg.com/configuration/yarnrc#packageExtensions
Essentially the packageExtensions of .yarnrc gives you a way to override the dependencies of packages.
In this case the problem is that debug declares supports-color as a peer-dependency rather than a dependency.

@atablash
Copy link

If I understand this correctly, the authors of the debug package actually intended to make supports-color an optional peer dependency, so the correct override is:

packageExtensions:
  "debug@*":
    peerDependenciesMeta:
      "supports-color":
        optional: true

This exact example is listed in the Official Yarn 2 Migration Guide.

@bodia-uz
Copy link

@atablash it's indeed listed in the official doc, but for some reason, it does not work. While Giorgio's solution works

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 a pull request may close this issue.

4 participants