Skip to content

Environment variable evaluation not working in index.html #5473

Closed
@marco-gagliardi

Description

@marco-gagliardi

Is this a bug report?

yes

Did you try recovering your dependencies?

yes

Environment

System:
OS: macOS High Sierra 10.13.6
CPU: x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
Binaries:
Node: 10.9.0 - /usr/local/bin/node
npm: 6.2.0 - /usr/local/bin/npm
Browsers:
Chrome: 70.0.3538.67
Safari: 12.0
npmPackages:
react: ^16.5.2 => 16.5.2
react-dom: ^16.5.2 => 16.5.2
react-scripts: ^2.0.3 => 2.0.5
npmGlobalPackages:
create-react-app: Not Found

Steps to Reproduce

  1. Add a condition script in your public/index.html file based on an env variable:
<script>
      '%REACT_APP_ENV%' === 'production' ?  console.log('production') : console.log('not production')
</script>
  1. Set a value for that env variable at build time: REACT_APP_ENV=production react-scripts build
  2. Inspect build/index.html

Expected Behavior

You should see

<script>console.log('production')</script>

Actual Behavior

you see:

<script>console.log('not production')</script>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions