question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Minification bug in production build that does not exist when using dev server

See original GitHub issue

Describe the bug

I tracked down the bug to a return statement that the minifier resolved to return null/nothing, but the dev server returned a component as expected.

Environment

CRA not ejected react-scripts 3.4.1

bug seen in Firefox, Safari and Chrome on Mac and PC

Steps to reproduce

class arrow function:

renderOption = (option)=>{
  const { wi } = this.props
    let sourceWi = wi
    return (
      // myVar1,
      // myVar2,
      // myVar3
      <MyComponent
        title={ sourceWi.title }
        revIndex={ option.revIndex }
        sourceWi={ sourceWi }
      />
    )
}

After npm run build, this code no longer returns a component.

Expected behavior

Arrow function should return MyComponent (which works fine using dev server)

Actual behavior

After running npm run build, it appears the minifier returns nothing. Even though the return statement wraps its content in parentheses (). Perhaps it is confused by the commented variables //

I corrected the bug by creating a variable and then returning it:

renderOption = (option)=>{
  const { wi } = this.props
    let sourceWi = wi
    const res = (
      // myVar1,
      // myVar2,
      // myVar3
      <MyComponent
        title={ sourceWi.title }
        revIndex={ option.revIndex }
        sourceWi={ sourceWi }
      />
    )
    return res // NOTE returning the const res instead of the parentheses builds and runs fine
}

To reproduce the behaviour of the bug I simply return nothing instead of res. This is why I think it is a minification problem that ignores the contents inside the parentheses.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:10

github_iconTop GitHub Comments

4reactions
sbuschcommented, Apr 29, 2020

See also #8687

1reaction
sbuschcommented, Jun 19, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack-dev-server not bundling even after showing bundle ...
The project seems to be working fine with just webpack cmd. It builds into my build folder and I can get it working...
Read more >
How I solved and debugged my Webpack issue through trial ...
When webpack bundles your source code, it can become difficult to track down errors and warnings to their original location.
Read more >
Read your production Angular Errors like a pro - Medium
We all want to build bug-free applications. We also know that it is ... Since this is production all file/method names are minified...
Read more >
Watch and WatchOptions | webpack
Webpack can watch files and recompile whenever they change. This page explains how to enable this and a couple of tweaks you can...
Read more >
Reactjs Build Production: Optimize Performance - CopyCat Blog
Introduction to Reactjs Build Production. For running your React.js project, there are two modes are available – development and Reactjs ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found