webpack-cli: Unknown argument: --env
Describe the bug
I’m trying to set my webpack env for configuration purposes with
webpack --env.platform=node
But, webpack-cli keeps throwing ⬢ webpack: Unknown argument: --env error to me
What is the current behavior?
webpack-cli refuses to read the flag and throw an error instead
To Reproduce Steps to reproduce the behavior:
Just try to add --env flag to any webpack command.
Expected behavior
webpack-cli should accept and set this variable correctly
Screenshots

Additional context
This works on 3.3.10. I’m currently using 4.0.0-beta.2
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 5
- Comments: 29 (12 by maintainers)
Commits related to this issue
- Upgrades `webpack-dev-server` and `webpack-cli` * Upgrades `webpack-cli` from v3.3.10 to v4.9.2 * [CHANGELOG](https://github.com/webpack/webpack-cli/blob/webpack-cli%404.9.2/CHANGELOG.md) * `webp... — committed to tmarkley/OpenSearch-Dashboards by deleted user 2 years ago
- Upgrades `webpack-dev-server` and `webpack-cli` (#1229) * Upgrades `webpack-cli` from v3.3.10 to v4.9.2 * [CHANGELOG](https://github.com/webpack/webpack-cli/blob/webpack-cli%404.9.2/CHANGELOG.md) ... — committed to opensearch-project/OpenSearch-Dashboards by deleted user 2 years ago
@snitin315 how?
it used to be as simple as
webpack --env.app=foobar --env.title=qwertybut, now this throws “Unknown argument” errorsthis creates variables with names
app=foobarandtitle=qwerty, and valuestruewebpack --env app=foobar --env title=qwertyThanks for the examples, migration of both config and scripts to use booleans will add a considerable overhead and current format seems not the most verbose thing to work with. I’ve opened https://github.com/webpack/webpack-cli/issues/1932 to track it, will PR soon
Since we’ve migrated our arg parser to commander so
--env.name="staging" --env.service="login"won’t be possible but we can do--env name=staging --env service=loginIs that something you can work with?This is a breaking change that really needs to be called out as such. In addition, I don’t think webpack-cli 4.x can claim compatibility with webpack v4 with this change – the
--env.prod=fooform is explicitly called out in the webpack v4 docs. If there is no desire to undo this change, then thepeerDependenciesshould change.I am having the exact same problem with the
modeflag. And yet the docs still include it, and the migration guide for webpack 4 -> 5 mentions it, so it’s pretty clear it hasn’t been removed… Very confused with this one.So, setting up the enviroment variables like this is the way to go:
--env prod=foo- no dot notation.Can there be some easy to find simple fix for this? A lot of people are going to be running into this now, I read the comments and I’m still not sure what the exact fix is
PR sent. Thanks.
I don’t want a config per application either, because they would all be the same. It would only complicate things.
Please don’t install
4.0.0-beta.2just yet. Unfortunately I published an incorrect version on npm, so sorry about that. Please keep using3.3.10or3.3.11.In
4.0.0-beta.2we removed--modeand--env. If you feel you’d need that argument back, feel free to leave a feedback hereAh okay so you have a single config for all applications, then
envis the way to go 👍@thealjey-eib for now yes, this is how the behaviour was restored when it was removed.
You can use
And use these variables to write conditional logic in your config, does it not cover your use case? If not, please give an example.
@anshumanv thanks but that link is not working for me. could you paste a summary or working example?
I’m seeing this issue in the 4.0.0 release