Describe the bug
I am trying to use [email protected] with [email protected]. I am using Yarn 2 with workspaces. When I run my build command webpack --config webpack.config.js it tells me that I need to install webpack-cli but I already installed it. Is PnP not supported?
What is the current behavior?
To Reproduce
Steps to reproduce the behavior:
Create a Yarn 2 project with workspaces.
Install webpack and webpack-cli to one of the workspaces.
webpackExpected behavior
A bundle is generated.
Actual behavior
Error:
CLI for webpack must be installed.
webpack-cli (https://github.com/webpack/webpack-cli)
We will use "npm" to install the CLI via "npm install -D".
Do you want to install 'webpack-cli' (yes/no): no
You need to install 'webpack-cli' to use webpack via CLI.
You can also install the CLI manually.
Additional context
Didn't work with webpack-cli v3 either.
That error from webpack, I can't reproducible
I can't reproduce the error. May be its the problem with Yarn PnP. Can you please show the output of node node_modules/.bin/webpack-cli info ?
For some reason I can't reproduce it with the exact same error anymore so I'm going to close the issue.
Ok, I could reproduce it again so reopening the issue.
Make sure that you install webpack and webpack-cli with
yarn workspace <your_workspace> add webpack webpack-cli
Here's the package.json of my workspace:
{
"name": "test",
"scripts": {
"build": "webpack",
},
"devDependencies": {
"typescript": "^3.8.3",
"webpack": "5.0.0-beta.14",
"webpack-cli": "4.0.0-beta.8"
},
}
@aman29271 I can't because when you use PnP there is no node_modules folder.
I have never used Yarn Pnp. But it looks like it uses some .pnp.js file to keep track of packages and dependencies. It needs installConfig:{"pnp":true} in package.json file, for more details about Yarn PnP see here. Instead of running node node_modules/.bin/webpack you need to run simply yarn webpack or yarn <package-name>because there is not any node_modules folder in Yarn PnP. So, for me it turns out to be working. Let me know if it works for you.
Just ran into this, and discovered that the above behavior happens when using yarn 2 in strict mode. In loose mode, it works for me.
For yarn 2 in strict mode, add this to your .yarnrc.yml:
packageExtensions:
webpack@*:
peerDependencies:
webpack-cli: '*'
peerDependenciesMeta:
webpack-cli:
optional: true
Thanks for sharing
@arcanis Do you think that this is something that could be added to plugin-compat?
@nicolo-ribaudo the actual fix is simply to call yarn webpack-cli instead of yarn webpack. I think it's a decent workaround, does that sound acceptable?
It is enough, I didn't notice that fix :upside_down_face:
Fix for webpack 5 is here: https://github.com/webpack/webpack/pull/11189
Fix for webpack 4 is here: https://github.com/webpack/webpack/pull/11190
Fixed on webpack side, if you faced with PnP problem again, feel free to open a new issue
Most helpful comment
For yarn 2 in strict mode, add this to your
.yarnrc.yml: