create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

Minified React error #152 - comments before JSX

Open hugomallet opened this issue 6 years ago • 58 comments

Since CRA 3.4.1 Probably a babel issue

The following code raise an error on built version :

import React from 'react';

const Component = props => {
    return ( // a comment
        <div>
            toto
        </div>
    );
};

export default Component;

After building the app, i get the following error :

react-dom.production.min.js:209 Error: Minified React error #152; visit https://reactjs.org/docs/error-decoder.html?invariant=152&args[]=Component for the full message or use the non-minified dev environment for full errors and additional helpful warnings. at react-dom.production.min.js:149 at za (react-dom.production.min.js:173) at vo (react-dom.production.min.js:262) at cu (react-dom.production.min.js:246) at ou (react-dom.production.min.js:246) at Zo (react-dom.production.min.js:239) at qo (react-dom.production.min.js:230) at Du (react-dom.production.min.js:281) at react-dom.production.min.js:284 at tu (react-dom.production.min.js:240)

Removing the comment fixes the error

hugomallet avatar Mar 21 '20 15:03 hugomallet

+1

Demerjianm avatar Mar 21 '20 19:03 Demerjianm

Since CRA 3.4.1 Probably a babel issue

The following code raise an error on built version :

import React from 'react';

const Component = props => {
    return ( // a comment
        <div>
            toto
        </div>
    );
};

export default Component;

After building the app, i get the following error :

react-dom.production.min.js:209 Error: Minified React error #152; visit https://reactjs.org/docs/error-decoder.html?invariant=152&args[]=Component for the full message or use the non-minified dev environment for full errors and additional helpful warnings. at react-dom.production.min.js:149 at za (react-dom.production.min.js:173) at vo (react-dom.production.min.js:262) at cu (react-dom.production.min.js:246) at ou (react-dom.production.min.js:246) at Zo (react-dom.production.min.js:239) at qo (react-dom.production.min.js:230) at Du (react-dom.production.min.js:281) at react-dom.production.min.js:284 at tu (react-dom.production.min.js:240)

Removing the comment fixes the error

I was able to resolve mine by removing the comments as well. Not sure of a fix yet.

Demerjianm avatar Mar 21 '20 19:03 Demerjianm

+1

ainannan2010 avatar Mar 22 '20 10:03 ainannan2010

Wasted 2 hours on this...thanks

zoink avatar Mar 23 '20 08:03 zoink

I have something like this because of comment, ref is not assigned in production but working fine in development.

Remove comments everything works fine

export const IndeterminateCheckbox = ({
  indeterminate,
  isDuplicateRow,
  isDisabled,
  label,
  ...rest
}) => {
  const ref = React.useRef();
  React.useEffect(() => {
    console.log(ref, "ref");
    if (ref.current) {
      ref.current.indeterminate = indeterminate;
    }
  }, [ref, indeterminate]);
  return (
    // some comment here
    <>
      <input {...rest} ref={ref} type="checkbox" />
    </>
  );
};

kyashrathore avatar Mar 27 '20 08:03 kyashrathore

Happens in 3.4.0 too

terebentina avatar Mar 30 '20 19:03 terebentina

Fyi I made a reproducible demo detailed in https://github.com/facebook/create-react-app/issues/8726 (and it happens in both 3.4.1 and 3.4.0 as stated above)

antoinerousseau avatar Mar 30 '20 19:03 antoinerousseau

omg thank you guys, i think that was a miracle i found this issue here. I already though i am crazy. Because this error happens only on production build and everything is fine on local dev server. And also interesting that error "happens" in last catch block before render component with comment, so i broke my brain trying to resolve any shit in this func but everything was fine.

ERRORthenBSOD avatar Mar 31 '20 23:03 ERRORthenBSOD

Thank guy, you really save me, my build successfully but PrivateRoute not working as it expected before I discovered the error, after 2 hours Thanks a lot

abduljeleelng avatar Apr 08 '20 17:04 abduljeleelng

This error just happened to me, what comments should I need to remove? only those inside the rendering part?

Moreover, if I have comments that wrapped in brackets, would it be okay to keep them?

danielpaz6 avatar Apr 19 '20 11:04 danielpaz6

@danielpaz6 try and let us know :)

antoinerousseau avatar Apr 19 '20 12:04 antoinerousseau

@danielpaz6 try and let us know :)

Well, it actually worked... I removed ALL the comments from the rendering part.

danielpaz6 avatar Apr 19 '20 12:04 danielpaz6

The only comments that work are the ones wrapped in brackets. The ones with '// ' will cause it to break.

bryanlamtoo avatar Apr 20 '20 18:04 bryanlamtoo

I used this regex in VSCode to find the troublesome comments: \(\s*\n?\s*//

jonnyelliot avatar Apr 23 '20 14:04 jonnyelliot

I've played with my codebase quite a bit over the last hour to see what breaks it. It looks like the code breaks when the comment is at the beginning of the return statement. My code doesn't seem to care when the comment is anywhere after the first JSX tag. I stand to be corrected though.

Very weird and unexpected, tbh.

KayO-GH avatar Apr 27 '20 20:04 KayO-GH

Was anyone able to find a corresponding upstream issue?

I have a similar problem with obscure runtime errors in production which cannot be reproduced in dev, reported at #8738

sbusch avatar May 01 '20 09:05 sbusch

Ran into this issue as well, probably from terser minification.

worked around this by:

return (
// @ts-ignore
<Component />
);

to

const elem = (
// @ts-ignore
<Component />
);

return elem;

bugzpodder avatar May 21 '20 17:05 bugzpodder

The only comments that work are the ones wrapped in brackets. The ones with '// ' will cause it to break.

I can confirm this is true, and it's only after return (, not a variable such as const elem = (

This causes the error

return (
// NOTE
<Component/>
)

These do not

return (
/* NOTE */
<Component/>
)
const elem = (
// NOTE
<Component/>
)

Duplicate https://github.com/facebook/create-react-app/issues/8809

stahlmanDesign avatar May 30 '20 14:05 stahlmanDesign

I just came across this today. Removing comments solved it. React Minified error #152

aneeshpanoli avatar Jun 08 '20 22:06 aneeshpanoli

Removing comments in JSX really sovle this problem. LOL....

splex7 avatar Jun 11 '20 05:06 splex7