-
-
Notifications
You must be signed in to change notification settings - Fork 27k
Minified React error #152 - comments before JSX #8687
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
Comments
+1 |
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
|
Happens in 3.4.0 too |
Fyi I made a reproducible demo detailed in #8726 |
omg thank you guys, i think that was a miracle i found this issue here. I already though i am crazy. |
Thank guy, |
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 :) |
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: |
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:
to
|
I can confirm this is true, and it's only after This causes the error return (
// NOTE
<Component/>
) These do not return (
/* NOTE */
<Component/>
) const elem = (
// NOTE
<Component/>
) Duplicate #8809 |
I just came across this today. Removing comments solved it. |
Removing comments in JSX really sovle this problem. LOL.... |
This problem (or at least an aspect of it) seems to be fixed since Steps to reproduce the fix, based on @antoinerousseau's repro from #8687 (comment):
I'm ejecting to prove it's fixed after upgrading IMPORTANT: if you change the build setup, do not forget to I don't know if other types of comments are fixed, the repro mentioned above tests only <p>Should display OK below:</p>
{DATA.map(({ id, value }) => (
// this is a comment
<p key={id}>{value}</p>
))}
</p> Unfortunatley, It's time for a new CRA release... Update 1: I tested with code from @hugomallet's original issue const Component = props => {
return ( // a comment
<div>
toto
</div>
);
}; and this is also fixed with Update 2: according to the latest commits to |
@antoinerousseau isnt another way? or this is just the way it should be ? |
@Nerfi if your previous version is built with this bug, I don't see how you can fix it without fixing your code and then rebuilding. If you are not used to React apps development and production releases, you can read more at https://create-react-app.dev/docs/production-build/ |
@antoinerousseau Thanks for all the info and the help!! |
I removed all comments from my whole application still this issue is not resolved |
The problematic comments are most likely in dependencies. |
@israrface44 can you please share a minimal reproduction of the issue? |
Wasted my 3 hours.... remove comments works for me |
hopefully this does it, see here: facebook/create-react-app#8687
Seems to be caused by a bug in babel: facebook/create-react-app#8687
I had the same issue and removed all my comments outside of the function or if it was in a class components put them outside of the return. This blog was very helpful. That fixed the issue for deployment for me as well |
I fixed this issue, I missed one of the comments from app. I removed and this issue was fixed. Thanks @antoinerousseau |
The page was not rendering when it was uploaded into the server, however, it was rendering in my localhost. In my case was the comments added into the functions and the class components. Move the comments outside of the functions block in each component and with the class components, I moved them outside of the return with minimal comments in render.
Braulio Calderon
… On Oct 23, 2020, at 9:33 AM, Israrulhaq23 ***@***.***> wrote:
@israrface44 can you please share a minimal reproduction of the issue?
I fixed this issue, I missed one of the comments from app. I removed and this issue was fixed.
Thanks @antoinerousseau
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Issue is still here. |
I solved this problem by this blog. import React from 'react';
function Welcome(props) {
return (
// Welcome App
<div>
Welcome to Resume Backend
</div>
);
}
export default Welcome; We have to remove the line // Welcome App |
I implemented a custom /*
This is to avoid this bug
https://github.com/facebook/create-react-app/issues/8687
It will throw eslint error if you insert inline comments in the first two lines of a return statement
*/
module.exports = {
rules: {
'no-comments-at-jsx-return-start': {
create: function (context) {
return {
ReturnStatement: function (node) {
const comments = context.getCommentsInside(node)
comments.forEach(comment => {
if (comment.type === 'Line') {
if (
node.loc.start.line === comment.loc.start.line ||
node.loc.start.line === comment.loc.start.line - 1
) {
context.report(node, 'Do not insert comments in return statement first two lines')
}
}
})
}
}
}
}
}
} You probably want to apply this only to "overrides": [
{
"files": [
"src/**/*.tsx"
],
"excludedFiles": "*.test.*",
"rules": {
"my-project/no-comments-at-jsx-return-start": "error"
}
}
] Of course the are pitfalls:
It can be improved but I did not want to spend more time on it. It helped me prevent breaking my compiled app again (it happened twice before). |
…roken transpilation, see facebook/create-react-app#8687.
This doesn't seem like an issue with Create React App itself. |
@iansu I guess it seems to be a problem with the dependency that Create React App had (or still has?) on certain versions of It was a while ago though, so not sure if this issue is still present in the newer versions of Create React App. |
Am currently experiencing the same error, tried removing all comments yet the error still occurs. |
I had the same error when having a comment like /** TODO: |
@Instrumedley Maybe you should pay more attention to the position of the comment instead of the comment itself. |
x2 Aun tengo el problema |
https://reactjs.org/docs/error-decoder.html/?invariant=152&args%5B%5D=ni I've deleted all the comments and return; |
Minified React error #152 I solved this problem like this:-- |
Since CRA 3.4.1
Probably a babel issue
The following code raise an error on built version :
After building the app, i get the following error :
Removing the comment fixes the error
The text was updated successfully, but these errors were encountered: