Buffer is not defined in react-pdf

I try to use the react-pdf library to generate pdf.

But when I do this I have an error like this :

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: { "assert": require.resolve("assert/") }' - install 'assert' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "assert": false } resolve 'assert' in 'C:\Users\SMAX\OneDrive\Projets Autres\exxotax_react\node_modules\browserify-zlib\lib'

Now, after installing some packages the React/Webpack is compiled from npm run start. But I have the following error :

Buffer is not defined And nothing appear on screen.

How can I fix it ? I tried :

  • Install all libraries needed
  • Watch on internet some solution

The only solution I saw was somethin like :

Creating a webpack.config.js and add :

resolve: {
extensions: [ '.ts', '.js' ],
fallback: {
    "stream": require.resolve("stream-browserify"),
    "buffer": require.resolve("buffer")
} },

But how can I add this lines in the config file ? Do I need a new config file/package.json ? If yes how can I do ?

Thanks a lot !


To extend create-react-app webpack config, you will need to use craco or rewired instead of react-scripts

Craco: https://github.com/gsoft-inc/craco

Rewired: https://github.com/timarney/react-app-rewired