redoc icon indicating copy to clipboard operation
redoc copied to clipboard

Getting error while rendering RedocStandalone

Open sentaur-athena opened this issue 1 year ago • 3 comments

Describe the bug I installed redoc and dependencies, created a simple react component that calls RedocStandalone and tested on localhost:3000. It returns the following error:

Error: fs.lstatSync is not a function
    at BaseResolver.eval (webpack-internal:///./node_modules/@redocly/openapi-core/lib/resolve.js:123:23)
    at Generator.next (<anonymous>)
    at eval (webpack-internal:///./node_modules/@redocly/openapi-core/lib/resolve.js:8:71)
    at new Promise (<anonymous>)
    at __awaiter (webpack-internal:///./node_modules/@redocly/openapi-core/lib/resolve.js:4:12)
    at BaseResolver.loadExternalRef (webpack-internal:///./node_modules/@redocly/openapi-core/lib/resolve.js:106:16)
    at BaseResolver.eval (webpack-internal:///./node_modules/@redocly/openapi-core/lib/resolve.js:153:30)
    at Generator.next (<anonymous>)
    at eval (webpack-internal:///./node_modules/@redocly/openapi-core/lib/resolve.js:8:71)
    at new Promise (<anonymous>)

This is the code for my component:

import React from 'react';
import {RedocStandalone} from 'redoc';

export default function RedocComponent() {
  return (
    <div>
      <RedocStandalone specUrl="localhost:3000/open-api-new.json" />
    </div>
  );
}

Note that I already built the demo on redoc using the same json so the format there shouldn't be a problem. But also it's an fs issue so not related.

sentaur-athena avatar Aug 02 '23 18:08 sentaur-athena

Commenting to add that I upgraded node to 20.5.0 where lstatSync is supported and still experiencing this.

sentaur-athena avatar Aug 02 '23 20:08 sentaur-athena

@ZyzychO please take a look. Thank you!

nalesnichok avatar Aug 08 '23 11:08 nalesnichok

@sentaur-athena We appreciate your patience!

The issue happens because React app doesn't see the file open-api-new.json by the path: localhost:3000/open-api-new.json"

There are 2 possible ways to fix it.

  1. Host your API definition online. Example: specUrl="http://petstore.swagger.io/v2/swagger.json"
  2. Import it as a component, please check the screenshot attached.
Screenshot 2023-08-09 at 18 56 13 Screenshot 2023-08-09 at 18 54 59

ZyzychO avatar Aug 09 '23 15:08 ZyzychO