← All tasks
javascriptwebpack/webpack-cli #1815Not a task: not reproduced

package-utils cannot resolve external commands

envgap__webpack__webpack-cli-1815

01 / FAILURE SIGNATURE

As reported upstream

Error: @webpack-cli/package-utils tried to access @webpack-cli/info, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.
Not a benchmark task.
  • In a clean container the reported failure did not reproduce, or the known fix did not make the project run.

02 / ENVIRONMENT RECIPE

Base commit
258219a3bb606b228636e6373a3d20413c1f660e
Manifest
packages/utils/package.json
Reproduce
Awaiting issue-specific recipe
Run under trace
Awaiting a meaningful runtime command

03 / ORIGINAL ISSUE TEXT

webpack/webpack-cli #1815 · read the original issue
**Describe the bug**

`packageExists` in `@webpack-cli/package-utils` is used to resolve external commands: https://github.com/webpack/webpack-cli/blob/a515b76434a5031aada10f660975ea03d2a66218/packages/package-utils/src/packageUtils.ts#L64-L71



However, since external command packages, such as `@webpack-cli/info`, aren't declared as a dependency, `@webpack-cli/package-utils` shouldn't be able to require them.



This is especially an issue for Yarn 2 PnP as it [requires all dependencies to be explicitly declared](https://yarnpkg.com/features/pnp) to link them ([Yarn rulebook](https://yarnpkg.com/advanced/rulebook#packages-should-only-ever-require-what-they-formally-list-in-their-dependencies)).



If Yarn cannot resolve the dependency, it falls back to the top level if `pnpFallbackMode` is `depenencies-only` (default) or `all`. So it's possible to resolve external commands, but not default commands included in the `webpack-cli`.



For instance, if the dependency tree of a project is:

```

project

├─D> @webpack-cli/xxx

└─D> webpack-cli

     ├─D> @webpack-cli/package-utils

     └─D> @webpack-cli/info

```

`webpack xxx` works but `webpack info` doesn't work because `@webpack-cli/package-utils` cannot resolve `@webpack-cli/info`. `webpack xxx` doesn't work if `pnpFallbackMode: none`.



To summarize:

1. ~`@webpack-cli/package-utils` cannot resolve default commands (#1816)~

2. `@webpack-cli/package-utils` cannot resolve external commands with `pnpFallbackMode: none`



**What is the current behavior?**

```

$ webpack info

Error: @webpack-cli/package-utils tried to access @webpack-cli/info, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.



Required package: @webpack-cli/info (via "@webpack-cli/info")

Required by: @webpack-cli/package-utils@npm:1.0.1-alpha.4 (via @webpack-cli-package-utils/node_modules/@webpack-cli/package-utils/lib/)



Require stack:

- @webpack-cli-package-utils/node_modules/@webpack-cli/package-utils/lib/packageUtils.js

- @webpack-cli-package-utils/node_modules/@webpack-cli/package-utils/lib/index.js

- webpack-cli/lib/commands/ExternalCommand.js

- webpack-cli/lib/utils/arg-parser.js

- webpack-cli/lib/webpack-cli.js

- webpack-cli/lib/bootstrap.js

- webpack-cli/bin/cli.js

- webpack/bin/webpack.js

    at internalTools_makeError (.pnp.js:21227:34)

    at resolveToUnqualified (.pnp.js:22185:23)

    at resolveRequest (.pnp.js:22277:29)

    at Object.resolveRequest (.pnp.js:22343:26)

    at Function.external_module_.Module._resolveFilename (.pnp.js:21460:34)

    at Function.external_module_.Module._load (.pnp.js:21325:48)

    at Module.require (internal/modules/cjs/loader.js:1025:19)

    at require (v8-compile-cache/v8-compile-cache.js:161:20)

    at packageExists (@webpack-cli/package-utils/lib/packageUtils.js:58:9)

    at Function.run (webpack-cli/lib/commands/ExternalCommand.js:27:22)

```

```

[webpack-cli] The command moved into a separate package: @webpack-cli/info



? Would you like to install @webpack-cli/info? (That will run yarn add -D @webpack-cli/info)

```



**To Reproduce**

```sh

yarn set version berry

yarn init

echo -e 'packageExtensions:\n  "@webpack-cli/package-utils@*":\n    dependencies:\n      "cross-spawn": "^7.0.0"' >> .yarnrc.yml # Workaround for issue already fixed in master

yarn add -D webpack@^5.0.0-rc.0 webpack-cli@^4.0.0-beta.9

yarn webpack info

```



**Expected behavior**

`webpack info` and `webpack xxx` (`xxx` is an external command) to run

Continue on GitHub ↗

04 / LABELS

Labels from the report text only; not yet run

No supported category has been assigned.

Label rules and the text that matched
[]