esxjs / esx

Like JSX, but native and fast
MIT License
654 stars 11 forks source link

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 4 years ago

irudoy commented 4 years ago

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 commented 3 years ago

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 commented 2 years ago

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 commented 1 year ago

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