-
-
Notifications
You must be signed in to change notification settings - Fork 126
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
"Error: Cannot read property '0' of undefined" when using react-component with NextJS #197
Comments
I have tried with the bare minimum component, which is this, and it also throws the same error. <AsyncApi schema={{ asyncapi: '2.0.0' }} config={{ showErrors: process.env.NODE_ENV !== 'production' }} /> |
I tested your schema with playground using latest version of react component, and it works fine https://asyncapi.github.io/asyncapi-react/ Have you seen the problem we have with next.js #177 ? |
Yes, but o think it's a different issue. In fact, I have commented there too.
If it works there, then maybe the issue is because of the "dynamic import" workaround needed for NextJS. I'll try on a different react app. Do you know if there's any way I can debug what's the object from which is trying to read the property 0? |
The only quick idea I have is that maybe we have a bug that we expect you to have Servers Object 🤷♂️ and you do not have it (you do not have to have if of course) but initially we might assume it is standard and everybody has one. Add it to your file and check out, or just test your code against https://raw.githubusercontent.com/asyncapi/asyncapi/2.0.0/examples/2.0.0/streetlights.yml otherwise, best if you share your project somewhere on GitHub and we can jump there maybe 🤔 |
oh, wait, I'm stupid with Server Object 😄 it would not work with react playground then anyway 🤦 |
I made a codesandbox app with your @acelaya schema and everything is good in pure browser-side react app https://codesandbox.io/s/asyncapi-react-component-in-action-forked-ik0ud?file=/src/index.js I am wondering, but probably that as you wrote, problem is with |
Yep, I was also testing that. It works just fine on a create-react-app project, but using create-next-app + this I'll try to investigate a bit more to see if I can find out what's the root cause. Maybe I can report it to NextJS if so. The weird thing is that I was using I'm also updating from NextJS 9 to 10 at the same time, so maybe that's the problem. I'll try other combinations and come back to you with my findings. |
@acelaya awesome, waitin for news. Regarding the component under the old scope, yes, you remember the name correctly, we changed it just recently. Right before switching scopes, we released version 0.16 with this https://github.com/asyncapi/asyncapi-react/pull/176/files. You can try |
@acelaya Do you remember old integration stuck in your app, I mean version of |
The project is currently using these dependencies https://github.com/shlinkio/shlink-api-spec-ui/blob/v1.4.1/package.json So, NextJS 9.3 and @kyma-project/asyncapi-react 0.5 I was updating all dependencies at once though. This afternoon I'll try other combinations to see when it break. The project is running here https://api-spec.shlink.io/async-api/ |
So, I have tested all minor versions of
I'll try next all those with NextJS 10, but I think the result will be the same. |
Yep, same result with NextJS 10. I have tried to check what changed between 0.12 and 0.13, where this error seems to start appearing, but I can't really tell by the diff v0.12.0...v0.13.2 Also, it could be that it was introduced earlier, but some of the other errors actually hid it. Or even the other way around. Any ideas? Do you know what could have changed in those versions? |
@acelaya Thanks for info! I made dummy debug by I will also create small PR to console.error errors throwed by parser, because at the moment we only intercept error and show it in component and as we see this is not a good idea for debuging. |
Thanks for checking this @magicmatatjahu I'll try with the web-component and see if it works. I'll also try to dig a bit further later on the Also, since you say you console.logged the error in |
and this error occurred inside |
@acelaya hey, so how did it end up on your side? you use web-component or? |
I'm afraid I didn't get to try. I think I started but I found some blocker. Not sure what was it though, it's been a while. I'll give it another try. |
This issue has been automatically marked as stale because it has not had recent activity 😴 |
@acelaya Hello! Sorry for waiting, but please check this comment #177 (comment) It should fix your problem. Let us know if everything is ok. If you have questions, feel free to ask. :) |
Thanks @magicmatatjahu. I'm testing the solution in the comment, and it's looking good so far 🙂. Thanks! |
Description
I'm trying to use this component inside a NextJS application. The component looks like this:
I can see the
url
being loaded in the browser developer tools, but once loaded I see this error:I have also tried hardcoding the spec in the
schema
property, with the same result, so I think I may have some invalid property somewhere.However, if I test that schema in the playground https://playground.asyncapi.io/, it doesn't throw any error and everything works.
I also see this warning in the browser's console, but I can't confirm it is related.
Expected result
The component properly loads in the UI, with no errors
Actual result
Error: Cannot read property '0' of undefined is displayed
Steps to reproduce
Use the code snippet above on a NextJS app
The text was updated successfully, but these errors were encountered: