Minified React error #152 - comments before JSX
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
+1
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.
+1
Wasted 2 hours on this...thanks
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" />
</>
);
};
Happens in 3.4.0 too
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)
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.
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
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 try and let us know :)
@danielpaz6 try and let us know :)
Well, it actually worked... I removed ALL the comments from the rendering part.
The only comments that work are the ones wrapped in brackets. The ones with '// ' will cause it to break.
I used this regex in VSCode to find the troublesome comments: \(\s*\n?\s*//
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.
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
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;
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
I just came across this today. Removing comments solved it. React Minified error #152
Removing comments in JSX really sovle this problem. LOL....