Closed skamansam closed 1 month ago
https://github.com/APIDevTools/swagger-parser?tab=readme-ov-file#browser-support
To use Swagger Parser in a browser, you'll need to use a bundling tool such as Webpack, Rollup, Parcel, or Browserify. Some bundlers may require a bit of configuration, such as setting browser: true in rollup-plugin-resolve.
So you'll need to install the polyfills
pnpm add -D @esbuild-plugins/node-globals-polyfill @esbuild-plugins/node-modules-polyfill
And update your vite config
vite.config.ts
import { defineConfig } from 'vitest/config';
+ import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
+ import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill';
export default defineConfig({
optimizeDeps: {
esbuildOptions: {
plugins: [
+ NodeGlobalsPolyfillPlugin({
+ process: true,
+ buffer: true
+ }),
+ NodeModulesPolyfillPlugin()
]
}
}
});
Can you try v11.6.5?
when I try to use it in the browser, with Vite, I get the following error in the console:
Vite doesn't use
process.env
, it usesimport.meta
. I'm not sure if this is in one of your libs, or an included lib, but regardless, this lib doesn't work with Vite.