Module not found: Error: Can't resolve 'buffer'

See original GitHub issue

Hi, I believe https://github.com/diegomura/react-pdf/pull/1891 should fix problem with create-react-app v5 using webpack 5. But unfortunately when creating fresh cra application with instruction from quick-start https://react-pdf.org/ I see following errors:

Failed to compile.

Module not found: Error: Can't resolve 'buffer' in '/Users/user/Documents/Code/cra-pdf-test/node_modules/base64-to-uint8array'
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 }
ERROR in ./node_modules/base64-to-uint8array/index.js 8:10-32
Module not found: Error: Can't resolve 'buffer' in '/Users/user/Documents/Code/cra-pdf-test/node_modules/base64-to-uint8array'

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 }

webpack compiled with 1 error
Files successfully emitted, waiting for typecheck results...
Issues checking in progress...
No issues found.

here is reproduction repo: https://github.com/Gratify-Ocelot/cra-pdf-test

_Originally posted by @Gratify-Ocelot in https://github.com/diegomura/react-pdf/issues/1891#issuecomment-1240563473_

here is proposed fix by @carlobeltrame https://github.com/diegomura/react-pdf/pull/1891#issuecomment-1240631229

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:6
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
R-Gallaghercommented, Sep 16, 2022

I ran into the same issue and seem to have fixed it. I hope this helps?

I was on react-app-rewired, but thought that recent updates here would allow me to transition off back to Create React App. This worked in development, and on local builds, but when I tried to deploy to Netlify, I got the error shown in this issue.

I fixed it with two changes:

  1. Using the changes described here relevant to Webpack 5: https://github.com/wojtekmaj/react-pdf#configure-pdfjs-worker
  2. running npm install --save buffer

Note that this works on Create React App, and I did not have to write a config override.

1reaction
diegomuracommented, Nov 7, 2022

Done!

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Can't resolve 'buffer' in 'C:\Portal\\node_modules ...
I got it working by installing the missing modules. npm install assert --save npm install buffer --save.
Read more >
Error while building with webpack #417 - Issuehunt
src/index.js 1:17-45 ERROR in ./node_modules/readable-stream/lib/_stream_readable.js 46:13-37 Module not found: Error: Can't resolve 'buffer' in ...
Read more >
Webpack 5 errors | ImmutableX Documentation
Module not found : Error: Can't resolve 'https' in ... stream-browserify assert stream-http https-browserify os-browserify url buffer process.
Read more >
Resolve | webpack
When enabled, webpack would prefer to resolve module requests as relative requests instead of using modules from node_modules directories. webpack.config.js
Read more >
How to fix 'Module not found: Can't resolve 'http' in ... - YouTube
Basically, just change 'react-scripts' to 4.0.2 in your package.json and run `npm install` again :D Follow me on Twitter: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found