You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am having the exact same problem with the mode flag. 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.
Reacted by George Campbell, Cristopher, Nathan H. Leung, Phebe S and JLUssh
Please don't install 4.0.0-beta.2 just yet. Unfortunately I published an incorrect version on npm, so sorry about that. Please keep using 3.3.10 or 3.3.11.
In 4.0.0-beta.2 we removed --mode and --env. If you feel you'd need that argument back, feel free to leave a feedback here
it used to be as simple as webpack --env.app=foobar --env.title=qwerty
but, now this throws "Unknown argument" errors
this creates variables with names app=foobar and title=qwerty, and values true webpack --env app=foobar --env title=qwerty
Reacted by alleqs, Roman Sorin, Nikolay Ermolenko and Brendan Grainger
Reacted by Git-me-outta-here, Arthur Beaulieu, Ligia Andreica, Daniel Strobusch, Ru, alleqs, Edan Kriss, Roman Sorin, Nikolay Ermolenko, Roberto Sannino and 1 more
Reacted by Roman Sorin, Nikolay Ermolenko and JLUssh
Thanks 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 #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=login Is that something you can work with?
Reacted by thealjey-eib, Joe Gasewicz, guiann, Paul Mackinlay, Danny Davenport, Jorge Fuentes, Eugene, Andor Polgár, Nicholas Pedroso, Eugene Gluhotorenko and 1 more
Reacted by Joe Gasewicz, Fabe, René Zschoch, Victor Glindås, mm and Nicholas Pedroso
@anshumanv my example is a multi-application project
I have an "applications" folder and I want to build any one of them by name.
Maybe env is not ideal, I do not know, but I have not been able to find a better way to pass custom variables into webpack.config.js
I cannot hardcode the names of every app in webpack.config.js, and even if I did a boolean value is just not suitable for getting a single value from a list.
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=foo form is explicitly called out in the webpack v4 docs. If there is no desire to undo this change, then the peerDependencies should change.
Reacted by Joseph Frazier, Katie Byers, Armin Varshokar, Joey Curosli, RM-Eric and CJ Thompson
Activity
lobsterkatie commentedon Feb 11, 2020
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.ematipico commentedon Feb 12, 2020
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 hererobertlevy commentedon Oct 11, 2020
I'm seeing this issue in the 4.0.0 release
anshumanv commentedon Oct 11, 2020
Hi, @robertlevy we've changed the env flag format in v4 because we changed the arg parser, new docs will be released on official site soon. Meanwhile, you can use CLI docs from this deployment - https://vercel.com/webpack-docs/webpack-js-org/e6mjiydwu
robertlevy commentedon Oct 11, 2020
@anshumanv thanks but that link is not working for me. could you paste a summary or working example?
anshumanv commentedon Oct 11, 2020
@robertlevy ofcourse! You should get a good idea from this test - https://github.com/webpack/webpack-cli/blob/master/test/config/type/function-with-env/function-with-env.test.js
Let us know if you run into any problems 😄
thealjey-eib commentedon Oct 12, 2020
@anshumanv
so, env now only supports boolean values?
I need to be able to pass arbitrary strings from the command line.
snitin315 commentedon Oct 12, 2020
@thealjey-eib You can pass any arbitrary string from the command line.
thealjey-eib commentedon Oct 12, 2020
@snitin315 how?
it used to be as simple as
webpack --env.app=foobar --env.title=qwertybut, now this throws "Unknown argument" errors
this creates variables with names
app=foobarandtitle=qwerty, and valuestruewebpack --env app=foobar --env title=qwertyanshumanv commentedon Oct 12, 2020
@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.
fabianmarcus commentedon Oct 12, 2020
I am used to do it this way:
Now I get
[webpack-cli] Unknown argument: --env.service=staging[webpack-cli] Unknown argument: --env.name=login.What's the working equivalent in Webpack CLI 4.x and Webpack 5.x?
When I change the syntax to your example, the properties in
envare just booleans:But that's not what I need.
anshumanv commentedon Oct 12, 2020
Thanks 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 #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?fabianmarcus commentedon Oct 12, 2020
Yeah, of course. Thanks!
thealjey-eib commentedon Oct 12, 2020
@anshumanv my example is a multi-application project
I have an "applications" folder and I want to build any one of them by name.
Maybe
envis not ideal, I do not know, but I have not been able to find a better way to pass custom variables intowebpack.config.jsI cannot hardcode the names of every app in
webpack.config.js, and even if I did a boolean value is just not suitable for getting a single value from a list.2 remaining items
anshumanv commentedon Oct 12, 2020
Ah okay so you have a single config for all applications, then
envis the way to go 👍chenxsan commentedon Oct 18, 2020
@evolopment Maybe you can help fixing it :) Here's the source page https://github.com/webpack/webpack.js.org/blob/master/src/content/guides/environment-variables.md to edit.
snitin315 commentedon Oct 21, 2020
@cranphin see #1939 for new
--envformat.ZebraFlesh commentedon Dec 15, 2020
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.AsebWebDev commentedon Dec 22, 2020
So, setting up the enviroment variables like this is the way to go:
--env prod=foo- no dot notation.snitin315 commentedon Dec 22, 2020
@AsebWebDev yep exactly!
Upgrades `webpack-dev-server` and `webpack-cli`
Upgrades `webpack-dev-server` and `webpack-cli` (#1229)
alexander-akait commentedon Jun 15, 2022
Please open an issue in angular-cli repo
Carles11 commentedon Jul 18, 2022
(with versions "webpack": "^5.73.0" and "webpack-cli": "^4.10.0")
This solved the issue for me:
/package.json -->
"scripts": {
"start": "webpack --mode=development && nodemon server",
"build": "webpack --mode=production && NODE_ENV=production",
...
}
Hope it helps.