Skip to content

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

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

Closed
stahlmanDesign opened this issue Apr 8, 2020 · 10 comments

Comments

@stahlmanDesign
Copy link

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.

@sbusch
Copy link

sbusch commented Apr 29, 2020

See also #8687

@stale
Copy link

stale bot commented May 30, 2020

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@sbusch
Copy link

sbusch commented May 31, 2020

I dont think this is resolved, see other issues

@stale stale bot removed the stale label May 31, 2020
@sbusch
Copy link

sbusch commented Jun 19, 2020

Update: see my comment here #8687 (comment)

@stale
Copy link

stale bot commented Jul 19, 2020

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Jul 19, 2020
@stahlmanDesign
Copy link
Author

I see a lot of people saying:

  • "removing comments fixes it"
  • "the error is resolved when I remove a comment".
    Technically removing valid code is a workaround. The minification script in Babel or Webpack still needs to be resolved so that people writing valid code don't end up with errors.

@stale stale bot removed the stale label Jul 20, 2020
@stale
Copy link

stale bot commented Aug 22, 2020

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Aug 22, 2020
@stahlmanDesign
Copy link
Author

This issue is still open and it's due to webpack / babel

@stale stale bot removed the stale label Aug 23, 2020
@stale
Copy link

stale bot commented Oct 4, 2020

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Oct 4, 2020
@stale
Copy link

stale bot commented Oct 12, 2020

This issue has been automatically closed because it has not had any recent activity. If you have a question or comment, please open a new issue.

@stale stale bot closed this as completed Oct 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants