asyncapi-react: Can't import in a Docusaurus project - error `can't resolve 'http'`
Description
My goal is to deploy two docs (OpenAPI & AsyncAPI) together in the same place.
-
I generate a Docusaurus website using steps docusaurus-openapi. The result is at the “Initial commit” of the reproducible minimal example.
-
I add a custom react page as described in their doc and import a random react component in it (‘awesome-react-button’), and it works:
- I import the AsyncAPI React component (exact diff commit) but now it crashes:
Expected result
Import to work and not break everything.
Actual result
Compilation errors
Full errors snippet
Module not found: Error: Can't resolve 'http' in '/Users/achraf/exp_docs/docusaurus/my-website/node_modules/@apidevtools/json-schema-ref-parser/lib/resolvers'
Did you mean './http'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (/Users/achraf/exp_docs/docusaurus/my-website/node_modules/@docusaurus/core/node_modules, node_modules, /Users/achraf/exp_docs/docusaurus/my-website/node_modules).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }'
- install 'stream-http'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "http": false }
Module not found: Error: Can't resolve 'https' in '/Users/achraf/exp_docs/docusaurus/my-website/node_modules/@apidevtools/json-schema-ref-parser/lib/resolvers'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "https": require.resolve("https-browserify") }'
- install 'https-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "https": false }
Module not found: Error: Can't resolve 'stream' in '/Users/achraf/exp_docs/docusaurus/my-website/node_modules/avsc/etc/browser'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }
Module not found: Error: Can't resolve 'stream' in '/Users/achraf/exp_docs/docusaurus/my-website/node_modules/avsc/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }
Module not found: Error: Can't resolve 'zlib' in '/Users/achraf/exp_docs/docusaurus/my-website/node_modules/avsc/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "zlib": require.resolve("browserify-zlib") }'
- install 'browserify-zlib'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "zlib": false }
Module not found: Error: Can't resolve 'stream' in '/Users/achraf/exp_docs/docusaurus/my-website/node_modules/avsc/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }
client (webpack 5.88.0) compiled with 6 errors
Steps to reproduce
Checkout before/after this commit in the reproducible: https://github.com/AchrafAmil/DocusaurusAsyncAPI/commit/7370bc343020ff4a6632fa72edc58b9474e63bab
Troubleshooting
Web dev is really not my comfort zone so I might be doing/saying something wrong, but it seems like the AsyncAPI React component is using a node.js dependency that shouldn’t be there (?).
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (7 by maintainers)
@AchrafAmil another workaround, until a new version of the
AsyncApiComponentis released (nextbranch), is by using the Standalone Bundle loaded in the useEffect hook of a custom component:You may also load the standalone script in the scripts section of the docusaurus.config.js, if so, remeber to also manually load the stylesheet.
oh not cool 😞
you have 2 options:
httpdependency. I cannot commit to any dates. Unless @fmvilas planned something alreadyFWIW, I went for the (pretty savage but quick) workaround of simply putting the fat single-file html+css+javascript in a React component. It gives the following results: https://docs.nabla.com/server/copilot-listen-ws