reactjs – How to implement the mysql module on a React JS project with webpack 5

I am starting my first project in React JS and I would need to use a PhpMyAdmin database.
From what I understand I need to use the “mysql” module to be able to connect to the database from my project. However when I install it and try to use the connect function I get several errors like:

`Module not found: Error: Can’t resolve ‘buffer’ in ‘C:\Users\thoma\OneDrive\Documents\guardians-app\node_modules\core-util-is\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: { “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 }`

And this for all of the following modules :

  • buffer, crypto-browserify, util, url, stream-browserify, timers-browserify

And others without details on the error (no mentions of webpack 5):

I spent several hours trying several solutions found online but without success. In particular, I tried to use fallback false or polyfill. At best I managed to obtain a blank page indicating that modules were missing in the console (apparently precisely those that I indicated in fallback which therefore do not seem to be found).

I also tried using react-app-rewired without success.

Is there any specific documentation or process for using this module since the move to Webpack 5? I have the impression that nothing has been done with this module to facilitate its installation since the change.

thanks in advance !

Read more here: Source link