Open MateuszPe opened 8 months ago
Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.
Please try with latest 1.4.2
and also older node version. We do not test against node 20 yet and our internal playground builds well against node 18
Regrettably, I've encountered the same outcome even after testing the latest version of the component with both Node 18 and 20.
@derberg why asyncapi/react-component
needs fs
module? Does it need to interact with files?
@derberg could you help me with this?
experiencing it as well (tried to lower version to 1.3.8, still encountering the issue)
Can't resolve 'fs' in node_modules/@asyncapi/parser/esm
🤔 fs
comes from parser that has a read file functionality, but we had proper webpack in place to make sure package still works in browser 🤔
https://github.com/asyncapi/asyncapi-react/blob/master/library/webpack.config.js#L50
I'm stuck dealing with a recurring problem and can't seem to find a fix for it.
I have the same issue and tried to fix it by downgrading versions (which did not help).
We wanted to adopt AsyncAPI widely for our users, but not having UI for it is a no-go.
Webpack since version 5 no longer automatically adds polyfills for all native modules from nodejs, you have to add them yourself. asyncapi-react
and parser-js
itself has sideEffects: false
enabled which means that any unused code is automatically removed from the final bundle (treeshaking), however asyncapi-react
uses parser-js
underneath and it again uses libraries that parse and validate the AsyncAPI spec that is passed to the component. These libraries (like spectral
) have used modules from fs
and other native modules which is why webpack throws errors that fs
is used somewhere and needs to be discarded or treated as an "empty" module.
If you are using create-react-app
then you need to eject
config for webpack and add appropriate fallbacks for modules, if you are using nextjs
or remix
(or another react framrwork) then you should be able to configure webpack without ejecting the framework configuration like here: https://stackoverflow.com/questions/64926174/module-not-found-cant-resolve-fs-in-next-js-application/68098547#68098547
There is also an option to use component without parser-js
-> https://github.com/asyncapi/asyncapi-react/blob/master/library/src/without-parser.ts but then you have to parse and validate (and maybe, based on cases, stringify the spec to JSON) on your own and put that inside mentioned component without parser.
I forgot about one thing, asyncapi-react
has a special version with bundled code, with and without parser - unfortunately with ReactDOM on board - there should be also a version with "pure" component (as another issue), just use
import AsyncAPIStandalone from '@asyncapi/react-component/browser/standalone'
AsyncAPIStandalone.render(...)
docs: https://github.com/asyncapi/asyncapi-react/blob/master/docs/usage/standalone-bundle.md
but I don't remember if it still works.
I tried without-parser by slightly modifying the example codesandbox in your readme but something might be broken, nothing happens. I think this might be why there are so many downloads on NPM for 0.24.23
@derberg after two months this issue is still present. It there any plan to fix this issue?
I have tried the newest version with the node in version 18 and 20.
we need more support here in this project and prefer PRs with fixes.
@magicmatatjahu wouldn't be the best from developer experience if we make sure parser-js
also publish separately package without functionality of reading from file? Then we just make sure we use here more lightweight version of parser, without delegating workarounds to react components users.
Description
I am trying to use React component for rendering documentation. I cannot use it due to the problem with missing modules. I created new application with create react app (I am aware that it is deprecated)
Then I installed asyncapi-react:
I am using node
v20.11.1
.package.json content:
Expected result
Application renders provided anyncapi definition.
Actual result
Steps to reproduce
npx create-react-app async-api-check --template typescript
npm install --save @asyncapi/react-component
AsyncApi.tsx
:export const AsyncApi = () => { return <>
}
const schema =
asyncapi: '2.0.0' info: title: Example version: '0.1.0' channels: example-channel: subscribe: message: payload: type: object properties: exampleField: type: string exampleNumber: type: number exampleDate: type: string format: date-time
;