-
Notifications
You must be signed in to change notification settings - Fork 8.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
Better guidance for integrating Swagger UI >=4.6.x into webpack 5 based projects #7908
Comments
Update: As of
This is despite the fact that my + const webpack = require("webpack");
module.exports = {
mode: "development",
resolve: {
fallback: {
stream: require.resolve("stream-browserify"),
+ buffer: require.resolve("buffer/")
}
},
+ plugins: [
+ new webpack.ProvidePlugin({ "buffer": ["Buffer", "buffer"] })
+ ]
} |
I've produced #7946 which should remedy this issue completely. No |
Q&A (please complete the following information)
Content & configuration
To support the issue described below, I have created a minimal repro here:
https://github.com/scottohara/swagger-ui-webpack
git clone https://github.com/scottohara/swagger-ui-webpack.git
cd swagger-ui-webpack
npm install
webpack
index.html
in a browserHow can we help?
I have been successfully using Swagger UI (
<= 4.5.x
) for many years, in many different projects, including some that are built using webpack 5.As of version 4.6.0, Swagger UI is itself also now built using webpack 5.
Because webpack 5 no longer includes node polyfills by default, and Swagger UI depends on some of these node polyfils (and this is unlikely to change), developers upgrading to Swagger UI 4.6.0 or later in their own webpack 5 based projects must now explicitly add these polyfills. This is already causing some issues for people that are unaware of this.
The existing webpack samples are now out of date and will not work for webpack 5.
With a view to (hopefully) contributing a fresh set of webpack samples that do work with webpack 5, I set out to create the most minimal webpack 5 + Swagger UI example possible. But I failed....
Starting from a known good base (Swagger UI v4.5.2)
Starting with Swagger UI v4.5.2 (prior to it's upgrade to webpack 5), my minimal
package.json
file includes just three dependencies:...and my
webpack.config.js
file simply sets the mode todevelopment
(to aid debugging):The
src/index.js
file just imports and uses Swagger UI as normal:...and the
index.html
page is also quite minimal:Running
webpack
using the above configuration produces adist/main.js
file; and opening theindex.html
file in a browser renders the Swagger Petstore API as expected. ✅Upgrading to Swagger UI v4.6.2
The next step is to upgrade the version of Swagger UI to 4.6.2:
Running
webpack
at this point now yields errors relating to two missing node polyfills, and suggests installingbuffer
andstream-browserify
:Additionally, to silence the
webpack
errors, a fallback forstream
has to be added to thewebpack.config.js
file:Running
webpack
now finishes without error, and produces adist/main.js
bundle. ✅However, reloading the
index.html
page in the browser, nothing is rendered and the following error appears in the browser console:Further experimentation was applied to the
webpack.config.js
, including :resolve.fallback: { "buffer": require.resolve("buffer/") }
as suggested by webpackprocess
polyfillnew webpack.ProvidePlugin({ "buffer": ["buffer", "Buffer"] }
...but none of these resolves the
Invalid or unexpected token
error, and it is unclear exactly what is causing it.Conclusion
I like to think that I'm not a complete Swagger UI + webpack novice, but I'm having difficulty getting a minimal example to work with webpack 5 + Swagger 4.6.2 (recall that it started out working perfectly for Swagger 4.5.2).
I can only imagine how first time users might also struggle to get Swagger UI 4.6.x working in their projects; and I believe it would greatly help if the webpack samples were refreshed to include a working webpack 5 configuration.
The text was updated successfully, but these errors were encountered: