-
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
Version 4.10.3 causes next.js app to fail run due to a SyntaxError #7970
Comments
I've also run into this issue with Next.js Workaround for now is to downgrade to swagger-ui-react 4.6.1 |
I've also run into same issue with Next.js@12.1.4. I though downgrading swagger-ui-react to 4.8.1 can solve this problem but it was breaking my application after build. It was showing an error in UI This error is happening if you are using new swc minifier. I removed |
Can confirm that this error exist for v4.9.0 and up on a fresh next.js installation. |
It worked for me: import dynamic from "next/dynamic";
const SwaggerUI = dynamic(import('swagger-ui-react'), {ssr: false})
const Test = () => <SwaggerUI spec={data}/>
export default Test |
@DjVreditel |
@TannicArturo98 you are welcome |
That's the solution! 🙏 |
typescript will complain about spec not being a recognized property on swaggerUI with the dynamic import |
Hi everybody, Yes, v4.9.0 introduced true ESM build fragments for SwaggerUI. These new ESM build artifacts are expected to be used by bundlers and we primarily targetted webpack@5 and Create React App. We expected, there might be implications and we're trying to address those implication as they arise. The solution outlined by @DjVreditel looks good: import dynamic from "next/dynamic";
const SwaggerUI = dynamic(import('swagger-ui-react'), {ssr: false})
const Test = () => <SwaggerUI spec={data}/>
export default Test Anybody that's looking for a solution that don't use I did a fresh installation of Next.js and installed pages/index.js import SwaggerUI from 'swagger-ui-react';
import 'swagger-ui-react/swagger-ui.css';
export default function Home() {
return (
<SwaggerUI url="https://petstore.swagger.io/v2/swagger.json" />
)
} Then I installed next-transpile-modules and modified next.config.js /** @type {import('next').NextConfig} */
const withTM = require('next-transpile-modules')([
'swagger-ui-react',
'react-syntax-highlighter',
'swagger-client'
]);
const nextConfig = {
reactStrictMode: true,
}
module.exports = withTM(nextConfig); After these small changes in Now these are all workarounds, the goal is to try achieve the support for Next.js without any additional configuration. Let's see if we can get there.
|
Just in case anyone runs into the same issue - I tried the dynamic import solution, but still ran into the error transpiling while using |
Created a SwaggerUI wiki page https://github.com/swagger-api/swagger-ui/wiki/Seamless-Integration-with-Bundlers-&-Test-Tools where integration with Next.js is now documented. |
Similar to #7944 but for next.js
Q&A (please complete the following information)
Content & configuration
Describe the bug you're encountering
In next.js app build crashes on
To reproduce...
import SwaggerUI from 'swagger-ui-react';
Expected behavior
No err
Additional context or thoughts
It worked ok on 4.2.1
The text was updated successfully, but these errors were encountered: