redoc
redoc copied to clipboard
Getting error while rendering RedocStandalone
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.
Commenting to add that I upgraded node to 20.5.0 where lstatSync is supported and still experiencing this.
@ZyzychO please take a look. Thank you!
@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.
- Host your API definition online.
Example:
specUrl="http://petstore.swagger.io/v2/swagger.json"
- Import it as a component, please check the screenshot attached.