-
Notifications
You must be signed in to change notification settings - Fork 9k
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
Swagger-ui-react not working with nextjs since 5.3.2 #9243
Comments
Same issue here |
I think this is an issue with the underlying swagger-js library extending the When using the From the working machine, MDN: File indicates that this class has been available in the browser for quite a while, so my guess is the issue is with the version of Node used to build Next.js site. Alternatively, the file I linked above looks like it's under active development, maybe this issue will go away with the implementation of |
I tried your (@thirdender) suggestion of updating to the latest version of Node (v20.7.0) and that indeed seems to have solved the issue. However, I still believe it's a problem that it does not work with the LTS version of Node (which is marked as recommended on their website) so I'll leave the issue open. |
Hi everybody, Please have a look at: https://github.com/swagger-api/swagger-ui/wiki/Seamless-Integration-with-Bundlers-&-Test-Tools#nextjs The POC repo contains recipe how to get Next.js get working with Node.js >= 16. |
Hi @char0n , the POC Repo that you're mentioning is using javascript, what if I used typescript? the swagger-ui-react package still not working in my project, node: 18.x i also tried using node v16.x, but it's still not working. it is a bit of a problem since vercel only supports until node v18.x. |
Hi @afikrim, Added new table row to https://github.com/swagger-api/swagger-ui/wiki/Seamless-Integration-with-Bundlers-&-Test-Tools#nextjs. There is now a POC repo containing recipe how to get Next.js + TypeScript + swagger-ui-react get working with Node.js >= 16. |
Therefor we must using [email protected], otherwise, |
Nope you don't. Have a look at https://github.com/char0n/swagger-ui-nextjs and the usage of package.json: |
For next you can use class componnets only for client components you can import with dynamic and this fix the problem import dynamic from "next/dynamic";
const DynamicSwaggerUI = dynamic(() => import("swagger-ui-react"), {
ssr: false,
loading: () => <p>Loading Component...</p>,
});
const AdminDocPage = () => {
return <DynamicSwaggerUI url="https://petstore.swagger.io/v2/swagger.json" />;
};
export default AdminDocPage; |
I've tried all possible solution mentioned above but only two options worked for me:
I choose the second option because release date is too close. After release I will upgrade node to v20. |
HI @davulrich, Solution described in #9243 (comment) must work for you on Node.js >= 16. But upgrading to Node.js >=20 is the easiest option anyway. |
I've just tried to use your polyfil file and it works! Thanks a lot. I will upgrade node to v20 asap after the release since it's optimal solution. |
Getting the same issue as OP using: Next 14.1.4 next 14 drops the undici distributable, so after including undici 5.24.0 to get the polyfill to work, I'm still getting the same ⨯ node_modules/swagger-ui-react/swagger-ui-bundle.js (2:819183) @ eval |
Hi @Flip-Liquid, I've addressed support for https://github.com/char0n/swagger-ui-nextjs is now directly runnable on [email protected]. |
The issue persisted after using the node:buffer polyfill and also upgrading to Node v 20. I was able to get it working by serving the Swagger UI using the pages router as opposed to the app router. Any attempt to use the SwaggerUI component under the app router resulted in the same error
|
@Flip-Liquid I'm not seeing any of these errors in https://github.com/char0n/swagger-ui-nextjs And related to |
Created a PR so you can see the delta: Moving the Swagger UI page to the app router will resurface the issue, even if using Node v 20 |
@Flip-Liquid thanks, I can see it now. |
@Flip-Liquid I've issued #9855 where I've rewritten the swagger-ui-react from class component to function component. I've tested with https://github.com/char0n/swagger-ui-nextjs (+ your draft PR changes) and seeing no issues. I need a deep review for this PR. As a matter of fact, can I ask any participant of this issue to look at the PR? Thanks! |
SSR support released in https://github.com/swagger-api/swagger-ui/releases/tag/v5.17.0 |
Q&A (please complete the following information)
Content & configuration
Example Swagger/OpenAPI definition:
Not relevant (it's never loaded).
Swagger-UI configuration options:
Describe the bug you're encountering
After updating to swagger-ui-react to any version higher than 5.3.2 I get the error:
TypeError: Class extends value undefined is not a constructor or null
along with a stacktrace when compiling the page.Stacktrace (with redacted project path):
To reproduce...
Steps to reproduce the behavior:
swagger-ui-react
after 5.3.2 in a project running nextjs 13.Expected behavior
The module should compile without issues.
Screenshots
The stacktrace window, full stacktrace can be found above.
Additional context or thoughts
swagger-viewer-react worked fine with nextjs until updating to the newer versions (downgrading to 5.3.2 fixes the issue).
I have tried following the nextjs instructions provided in the stacktrace but the only one I could affect (the
use client
option) didn't work.Since the problem is specific to certain versions of swagger-ui (that doesn't seem to mention next-js or any relevant info in the changelog) the problem appears to be at this end.
The text was updated successfully, but these errors were encountered: