Create-react-app: dotenv-expand breaking build when "$" is used

Created on 2 Feb 2018  路  6Comments  路  Source: facebook/create-react-app

We use variables that include $ within the strings, which we don't want to be expanded. Escaping with \$ works fine when it occurs at the start of the string, but not anywhere else within the string.

Example:

REACT_APP_MYVAR=\$bar.baz <- works as expected, value is "$bar.baz"
REACT_APP_MYVAR=foo\$bar.baz <- I'd expect "foo$bar.baz" but I get "foo\.baz"

I also tried working around the problem, like so:

BAR=\$bar
REACT_APP_MYVAR=foo$BAR.baz

But it gave the same result of "foo\.baz"

bug underlying tools

All 6 comments

This sounds really annoying. Sorry.

Do you want to look into what's causing this?

This does appear to be a bug in dotenv-expand. It only looks for an escaped $ at the start of the string.

Yes. I think there a couple of ways to fix it:

  1. Only expand when the variable starts with $ (instead of when it doesn't start with \$). This would make it impossible to expand variables inside a string which is maybe okay.
  2. Check if each occurrence of $ in the string is escaped and only expand it if it's not

Check if each occurrence of $ in the string is escaped and only expand it if it's not

This makes sense to me. We should also document that behavior.

Fixed in [email protected].

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Aranir picture Aranir  路  3Comments

JimmyLv picture JimmyLv  路  3Comments

xgqfrms-GitHub picture xgqfrms-GitHub  路  3Comments

oltsa picture oltsa  路  3Comments

barcher picture barcher  路  3Comments