Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--env foo="" is true instead of being "". #2642

Closed
denis-migdal opened this issue Apr 17, 2021 · 5 comments · Fixed by #2643
Closed

--env foo="" is true instead of being "". #2642

denis-migdal opened this issue Apr 17, 2021 · 5 comments · Fixed by #2643
Labels

Comments

@denis-migdal
Copy link

Describe the bug

--env foo="" is true instead of being "".

To Reproduce

  1. Call webpack with the option --env foo=""
  2. In webpack.config.js foo is equal to true instead of "".

Expected behavior

Foo should be equal to "" instead of true.

@snitin315
Copy link
Member

Looking into it 👍

@snitin315
Copy link
Member

I was able to reproduce, I am working on a fix.

@snitin315
Copy link
Member

I think you will have to escape the character on the terminal with \ -

Can you try - webpack --env foo=\"\"

@denis-migdal
Copy link
Author

denis-migdal commented Apr 18, 2021

But then the value of foo would be "\"\"". i.e. a string "" instead of an empty string.

With one of the old version of webpack-cli, in my package.json I had something like :

build: "webpack .... --env DIR_PREFIX \"$DIR_PREFIX\" --env SRC "

That I could call : DIR_PREFIX="/"; npm run build target1,target2,target2".

With the new version it is written :

build: "webpack .... --env DIR_PREFIX=\"$DIR_PREFIX\" --env SRC=\\"

However, I have 2 issues :

  • if DIR_PREFIX is not specified instead of having the environment variable equals to en empty string, it is equal to true.
  • my SRC environment variable is prefixed by a space due to how the command npm run works.

I succeeded to easily find a workaround, but I think --env PARAM="" and --env PARAM should be different, the first giving an empty string, the second, true.

It would then enable to do :

env.PARAM = env.PARAM ?? defaut_param; // default value if env.PARAM not defined
env.PARAM = env.PARAM || defaut_param; // default value if env.PARAM not defined or is an empty string
env.PARAM = env.PARAM !== true || default_param; // default value if env.PARAM is defined but with no values specified.

@alexander-akait
Copy link
Member

Yep bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants