swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.41k stars 8.93k forks source link

window is not defined when running swagger-ui-react #6153

Closed johnwhitton closed 4 years ago

johnwhitton commented 4 years ago

Environment

Content & configuration

I'm running

Swagger-UI configuration options:

import React from 'react';
import classnames from 'classnames';
import Layout from '@theme/Layout';
import Link from '@docusaurus/Link';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import useBaseUrl from '@docusaurus/useBaseUrl';
import styles from './styles.module.css';
import SwaggerUI from "swagger-ui-react"
import "swagger-ui-react/swagger-ui.css"

function Home() {
  const context = useDocusaurusContext();
  const {siteConfig = {}} = context;
  return (
    <Layout
      title='Harmony Swagger'
      description="Harmony Swagger">
      <main>
      <SwaggerUI url="harmony.yml" />
      </main>
    </Layout>
  );
}

Describe the bug you're encountering

When running yarn run start the server is started and the swagger page shows and works.

When running 'yarn run build` I get the following error

ReferenceError: Buffer is not definedReferenceError: window is not defined
(undefined) ReferenceError: Buffer is not defined

Gist containing more detailed error is here

To reproduce...

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

yarn run build works

Additional context or thoughts

This seems similar to this issue for swagger-ui and this issue

hkosova commented 4 years ago

Duplicate of #6136.