Skip to content

[Bug] Accessing a missing peerDependency throws unlisted dependency error #265

@bgotink

Description

@bgotink

Describe the bug

Accessing a missing peer dependency from within a package leads to

Error: A package is trying to access another package without the second one being listed as a dependency of the first one

rather than the expected "module not found". Note that the package is in fact correctly listed as peer dependency.

This, in turn, leads to issues when packages (correctly) only catch "module not found" errors on optional (peer) dependencies, e.g. in

https://github.com/waysact/webpack-subresource-integrity/blob/ab1f5f9/index.js#L18-L25

To Reproduce

# setup empty repo with berry
yarn add webpack-subresource-integrity webpack@~4
yarn node -e 'require("webpack-subresource-integrity")'
bram:/private/tmp/berry-test $ yarn node -e 'require("webpack-subresource-integrity")'
                               
/private/tmp/berry-test/.yarn/virtual/webpack-subresource-integrity-virtual-fa8536a74ed9d56a6a5b6edfe52bbd2c49eae7e61c54a7282dde48f8c580d680/node_modules/webpack-subresource-integrity/index.js:23
    throw e;
    ^

Error: A package is trying to access another package without the second one being listed as a dependency of the first one

Required package: html-webpack-plugin (via "html-webpack-plugin")
Required by: webpack-subresource-integrity@virtual:d4a8200a055d0a559d4e2f8c86347d647b4c6f848b77e7e192fd716a7fd86e9e6ddd399fd1ed72078947940a10d55d13d32e330523252b20909b75b6f17ae1ad#npm:1.3.2 (via /private/tmp/berry-test/.yarn/virtual/webpack-subresource-integrity-virtual-fa8536a74ed9d56a6a5b6edfe52bbd2c49eae7e61c54a7282dde48f8c580d680/node_modules/webpack-subresource-integrity/index.js)

    at Object.makeError (/private/tmp/berry-test/.pnp.js:10899:19)
    at resolveToUnqualified (/private/tmp/berry-test/.pnp.js:12472:43)
    at resolveRequest (/private/tmp/berry-test/.pnp.js:12518:31)
    at Object.resolveRequest.maybeLog [as resolveRequest] (/private/tmp/berry-test/.pnp.js:12557:32)
    at Function.module_1.default._resolveFilename (/private/tmp/berry-test/.pnp.js:11994:37)
    at Function.module_1.default._load (/private/tmp/berry-test/.pnp.js:11915:45)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/private/tmp/berry-test/.yarn/virtual/webpack-subresource-integrity-virtual-fa8536a74ed9d56a6a5b6edfe52bbd2c49eae7e61c54a7282dde48f8c580d680/node_modules/webpack-subresource-integrity/index.js:20:23)
    at Module._compile (internal/modules/cjs/loader.js:701:30)

Environment if relevant (please complete the following information):

  • OS: macOS
  • Node version: 10
  • Yarn version: latest version downloaded via yarn policies set-version v2 and build of master at 27c1137

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions