Skip to content

npm run build produces broken code #9654

@rwoll

Description

@rwoll

Describe the bug

The following statement evaluates differently when run in React Dev mode versus
a production optimized build produced by create-react-app:

console.log(/[^\d\-a-z]/iu.exec("a"))

The code should print null in both settings, but prints a null in dev (correct) and a match (incorrect) in the production optimized build.

Did you try recovering your dependencies?

N/A - The repo starts from a fresh npx create-react-app run.

Which terms did you search for in User Guide?

regex, production vs dev build, terser

Environment

$ npx create-react-app --info
npx: installed 98 in 4.318s

Environment Info:

  current version of create-react-app: 3.4.1
  running from /$HOME/.npm/_npx/57675/lib/node_modules/create-react-app

  System:
    OS: macOS 10.15.6
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Binaries:
    Node: 14.7.0 - /usr/local/bin/node
    Yarn: Not Found
    npm: 6.14.7 - /usr/local/bin/npm
  Browsers:
    Chrome: Not Found
    Firefox: 80.0.1
    Safari: 13.1.2
  npmPackages:
    react: ^16.13.1 => 16.13.1 
    react-dom: ^16.13.1 => 16.13.1 
    react-scripts: 3.4.3 => 3.4.3 
  npmGlobalPackages:
    create-react-app: Not Found

Steps to reproduce

See full contained repro repo: https://github.com/rwoll/repro-create-react-app-regex

  1. Clone and navigate to repo:

    $ git@github.com:rwoll/repro-create-react-app-regex.git
    $ cd repro-create-react-app-regex
    
  2. Install dependencies:

    $ npm i
    
  3. Launch the app in dev mode:

    $ npm start
    

Observe true is displayed.

  1. Build the production optimized version of the app, and launch on port 4000:

    $ npm run build
    $ npx serve -s build -l tcp://localhost:4000
    

Observe false is displayed.

Both cases should be consistent and display true; however, something as part of
the production build (Terser?) is making the code wrong.

Expected behavior

true is displayed in both dev and prod envs.

Actual behavior

true is displayed in dev, false is displayed in prod.

Reproducible demo

https://github.com/rwoll/repro-create-react-app-regex

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions