Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stoplight element react failed with error #2483

Closed
dmuley17 opened this issue Dec 18, 2023 · 8 comments
Closed

Stoplight element react failed with error #2483

dmuley17 opened this issue Dec 18, 2023 · 8 comments
Labels
jira p/high t/bug Something isn't working triaged

Comments

@dmuley17
Copy link

I am trying to use Elements Dev Portal for REACT after following the steps mentioned below
https://meta.stoplight.io/docs/elements/11b969f962273-elements-dev-portal-in-react

Application is failing to load and giving error

Attached error snippet from browser

image

Could you please guide and provide possible solution to fix the issue.

@dmuley17
Copy link
Author

Compiled with problems:
×
ERROR in ./node_modules/@stoplight/json-schema-ref-parser/lib/util/url.js 29:0-38
Module not found: Error: Can't resolve 'url' in 'C:\Users\DnyaneshwarMuley\workspace\icedq-docs\node_modules\@stoplight\json-schema-ref-parser\lib\util'
Did you mean './url'?
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 (C:\Users\DnyaneshwarMuley\workspace\icedq-docs\node_modules\@docusaurus\core\node_modules, node_modules, C:\Users\DnyaneshwarMuley\workspace\icedq-docs\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: { "url": require.resolve("url/") }'
	- install 'url'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "url": false }
ERROR in ./node_modules/@stoplight/yaml-ast-parser/dist/src/type/binary.js 2:17-41
Module not found: Error: Can't resolve 'buffer' in 'C:\Users\DnyaneshwarMuley\workspace\icedq-docs\node_modules\@stoplight\yaml-ast-parser\dist\src\type'

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: { "buffer": require.resolve("buffer/") }'
	- install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "buffer": false }

@dmuley17
Copy link
Author

Can someone please help to resolve the issue ?

@chohmann
Copy link
Contributor

chohmann commented Jan 5, 2024

@dmuley17 we need more information to be able to help you:

  1. Are you using web components, angular, react, etc. flavor of elements?
  2. Can you provide a minimal reproducible example app that shows the error?

@dnascimento
Copy link

Same issue here

@dnascimento
Copy link

In https://github.com/stoplightio/json-schema-ref-parser/blob/master/lib/util/url.js#L31 , the code is requesting the NodeJS module url. Before webpack 5, this was polyfill by NodeJS but moving forward it needs to be added. Could you add it as a dependency?

@dmuley17
Copy link
Author

we are using react flavor of elements. Tried fixing all the as per web but still same issue persist and never got the success.

For minimal reproducible we just need to follow -

https://docs.stoplight.io/docs/elements/11b969f962273-elements-dev-portal-in-react

npx create-react-app my-dir --template @stoplight/elements-dev-portal

@chohmann chohmann added t/bug Something isn't working p/high triaged labels Jan 19, 2024
Copy link

This ticket has been labeled jira. A tracking ticket in Stoplight's Jira (STOP-92) has been created.

@mallachari
Copy link
Contributor

@dmuley17 since CRA is now using webpack 5 that doesn't come with node polyfills anymore they need to be added separately. The easiest way to do that is to include node-polyfill-webpack-plugin to CRA webpack config. This can be done either by:

  1. Ejecting CRA configuration:
  • running npm eject script
  • installing node-polyfill-webpack-plugin
  • adding NodePolyfillPlugin to config/webpack.config.js:
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
...
plugins: [
  // Other plugins...
  new NodePolyfillPlugin(),
]
  1. Using react-app-rewired package that overrides CRA webpack config without ejecting:
  • installing react-app-rewired
  • installing node-polyfill-webpack-plugin
  • overriding default scripts in package.json:
"scripts": {
  "start": "react-app-rewired start",
  "build": "react-app-rewired build",
  "test": "react-app-rewired test",
  "eject": "react-scripts eject"
}
  • creating config-overrides.js configuration file in root directory:
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");

module.exports = function override(config, env) {
  config.plugins.push(
    new NodePolyfillPlugin()
  );
  return config;
};

We'll update elements docs with that process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jira p/high t/bug Something isn't working triaged
Projects
None yet
Development

No branches or pull requests

5 participants