Berry: [Bug] `webpack` cannot access `webpack-cli` with workspaces

Created on 30 Oct 2019  路  6Comments  路  Source: yarnpkg/berry

Describe the bug

webpack-cli throws an error "One CLI for webpack must be installed." in a workspace but works fine in a single package.
I think this may be a major bug with binaries and workspaces in berry.

To Reproduce

Checkout the repro repository: https://github.com/HosseinAgha/yarn2-workspaces-webpack-bug-repro

bug external bug stale

Most helpful comment

Note that you can use packageExtensions to fix the problem in your repo.

All 6 comments

It's a Webpack bug. They are using require.resolve to check whether webpack-cli is installed, but they don't run it on behalf on their parent package. This causes Yarn to reject the resolution because webpack-cli isn't a dependency of webpack.

Three solutions:

  • As a short-term option, you can use yarn webpack-cli ..., which is the real name of the binary exposed by webpack-cli.

  • The webpack package should declare webpack-cli (and webpack-command) as optional peer dependencies. This formal declaration will give it access to its neighbour packages.

  • Or the webpack package should require webpack-cli on behalf of the userland code by using something similar to createRequire. The trick is to find on behalf of who should the call be made - my best guess would be process.env.INIT_CWD.

I've ran into the same issue but with webpack-dev-server:

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

Required package: webpack-cli (via "webpack-cli/bin/config-yargs")
Required by: webpack-dev-server@virtual:1e73a2e864eda574311f3ce8fb25ed7e0b40837cf3d41b48f72db6961ea7b29e054e2ef16981aea4a4b040cdb56a1a6f9fe63ce21114147e55edb38884db917e#npm:3.10.1

Since the command being ran is already yarn webpack-dev-server, I'm not sure how to get around this and get unblocked. Any ideas?

Edit: Just found this PR: https://github.com/webpack/webpack-dev-server/pull/2396 - guess I'll use that branch until it's merged.

Note that you can use packageExtensions to fix the problem in your repo.

Adding this to .yarnrc.yml got past it:

packageExtensions:
  webpack-dev-server@*:
    peerDependencies:
      webpack-cli: "*"

Is my issue a duplicate of this?

Hi! 馃憢

This issue looks stale, and doesn't feature the reproducible label - which implies that you didn't provide a working reproduction using Sherlock. As a result, it'll be closed in a few days unless a maintainer explicitly vouches for it or you edit your first post to include a formal reproduction (you can use the playground for that).

Note that we require Sherlock reproductions for long-lived issues (rather than standalone git repositories or similar) because we're a small team. Sherlock gives us the ability to check which bugs are still affecting the master branch at any given point, and decreases the amount of code we need to run on our own machines (thus leading to faster bug resolution faster). It helps us help you! 馃槂

If you absolutely cannot reproduce a bug on Sherlock (for example because it's a Windows-only issue), a maintainer will have to manually add the upholded label.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wojtekmaj picture wojtekmaj  路  3Comments

danreg picture danreg  路  3Comments

Santas picture Santas  路  3Comments

dzintars picture dzintars  路  3Comments

thealjey picture thealjey  路  4Comments