Repository navigation
v5 used to include polyfills for node.js core modules by default #11756
Description
Activity
I have the same issue as well
Reacted by Anvar, hundehausen, S V, Nicolas Sayer, Kevin Mulcrone, Burgil, albert, Bi0max, Ognian, 8spw and 78 moreme too
Reacted by Anvar, S V, Nicolas Sayer, Kevin Mulcrone, Burgil, Bi0max, Ognian, Ilja Denisovs, 0xshortcake, Nick and 26 moreReacted by mdornseifWebpack 5 no longer shims node builtin packages. Its a breaking change.
Reacted by pavlovp, Marcel Robitaille, Chris Frewin, Matt Butler , Angelo Geulin, Haneen, Fernando Estrada and jems-kickReacted by Tina, Will, Ian Brighton, Konstantin Lukaschenko, JM, aroshalva, ΔNDRΞW (reese), Bolicos, shawn98ag, rsuresh27 and 15 moreReacted by Paul Fears, tmeindle, Paul Oloyede, Anvar, Cyriaque DELAUNAY, Abraham Yeo, Burgil, Nagarjun, DengYiPeng, Ilja Denisovs and 55 moreI try to upgrade from v4.0.3 to 5.0.0 and It raise up the same error
Compiled with problems:
ERROR in ./src/App.js 1:40-111
Module not found: Error: You attempted to import /home/xxx/web/node_modules/react-refresh/runtime.js which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.
You can either move it inside src/, or add a symlink to it from project's node_modules/.Reacted by Omri Hecht, Anvar, S V, velikayikci, Burgil, deployer, alexanderm1, BaniGrisson, Tomeu, strblr and 1 moreWebpack 5 no longer shims node builtin packages. Its a breaking change.
Are we meant to eject for every app that relies on node builtin packages? Won't that be most production apps, since you will invariably import a node module that relies on this functionality
Reacted by Kevin Kirsche, Michel Moreau, Richard Harrah, Joseph Garrone, Courage Research, Omri Hecht, Paul Fears, Ng Bob Shoaun, Trung Vo, Jeremy Law and 125 moreReacted by tmeindle, Josias, Burgil, Nagarjun, 0xshortcake, Georgios Giatsidis, Yassine Qoraiche, Kole Myers, laureanray, Rick and 7 moreReacted by Jonah DempcyMy personal view:
I personally consider it bad practice to include code in the front-end that was ment for back-end usage.
From my experience:
I've seen developers of any experienced try adding back-end npm packages on the front-end.In Npm there is no clear difference to help out developers, it's "Node Packages" not "Browser Packages"
Package maintainers should ideally build node or browser specific bundles.
Again this is my personal view I support the move in Webpack, I'll of course bring it up in the maintainer group.
(Also see the release notes regarding webpack 5 - there's a note regarding this breaking change for further details)
For now it would be helpful to collect examples of front-end packages suffering from this issue.
(The examples would help us reevaluate the decision)Reacted by stunaz, Simone Romano, Sondre S. Jensen, Datner, Issa Nodehi, Paul Oloyede, danyreyna, Alex Warnes, PiotrZak, Vignesh Elangovan and 49 moreReacted by Joseph Garrone, Michael Mannseicher, Sebastian, Akshay Pathak, Paul Fears, Ng Bob Shoaun, Tobias Bohwalli, Trung Vo, tmeindle, hcwilk and 200 moreReacted by Max Malm and aumnyx-lead-devReacted by UpsidePotential, Darlington Nnam, Arbitar, Grality, mdornseif, Muhammed Rahif, Daniel Bahiense and aumnyx-lead-devReacted by Praveen Kumar, Rohit Kaushik, Kasweka Michael Mukoko and aumnyx-lead-devReacted by merlox, Dimitrije Sejat, npjd, Alison Haire, james-julius, Grality, Praveen Kumar and Kasweka Michael MukokoOur two main usages are:
- zlib
- crypto
Our back-end compresses some of its data to optimize storage as well as network transfer. Our UI then uses zlib to uncompress it.
Our UI can also login using OAuth and it uses the crypto randomBytes and createHash methods to generate data for that authorizationReacted by Shawn Mitchell, Matthew Beardsley, Tobias Bohwalli, Trung Vo, Andrew Tkachenko, Davi Medeiros, def-roth, matbee, John Hagen, Raja Kaleem Ullah and 43 moreReacted by danyreynaWebpack has some output about providing a fallback resolution, what's the correct way to supply that since we don't have access to the actual webpack config?
Reacted by michaelmarziani, Bernardo Graça, tmeindle, wscullen, Nathan Hayfield, Shan Siddiqui, S V, Ana, codeaid, Daniel Boggs and 108 moreTo toss in another example, the v5 upgrade showed me that the libraries for AWS Cognito use url:
> yarn build Creating an optimized production build... Failed to compile. Module not found: Error: Can't resolve 'url' in '/path/to/app/.yarn/cache/@aws-amplify-core-npm-4.3.10-e9277c22ab-77b7fe62d8.zip/node_modules/@aws-amplify/core/lib-esm' 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 } >If you were a direct user of webpack v4, upgrading to v5, you have a few options:
- stay on v4
- remove usage of polyfilled modules
- add polyfills
If I were in this situation, I'd be taking option 3. But as I understand it, that's not available today with non-ejected CRA.
It'd be nice if Webpack 5 had a single switch to flip, to restore v4's polyfill behavior. Then CRA could expose just that one switch. But there isn't: Webpack's migration guidance is to manually add polyfills to your webpack config.
https://webpack.js.org/blog/2020-10-10-webpack-5-release/#automatic-nodejs-polyfills-removed
Here are the polyfills that were formerly provided by webpack (note that the project is deprecated): https://github.com/webpack/node-libs-browser
..so what should CRA do?
Reacted by Davi Medeiros, Yair Sageev, S V, laurenttainturier, Daniel Boggs, Mark Adamson, Abraham Yeo, velikayikci, Jorge Gonzalez, David Higgins and 32 moreReacted by Ian da Conceição da Silva, Muhammad Azeem, Sumit Kushwaha and Muhammed RahifI've added a pr to gather feedback #11764
Reacted by Aleksandra Kojic, Tobias Bohwalli, Yair Sageev, Louis Stanko, Clayton Bell, Haneen, Nick Baughman and qiuzi | 秋子Same issue here. is there some documentation that we can follow for doing this migration?
Reacted by V. Giustino, Akshay Pathak, tmeindle, Anvar, smurfolan, Joel Thibault, Mel Massadian, Max Aigner, Andy Hahn, Nick Baughman and 3 moreI'm not sure it's entirely a polyfill issue. I'm getting the
Can't resolve 'fs'due to Handlebars, which (IIRC) should have been prevented by itsbrowsersetting in package.json.Reacted by Morten N.O. Nørgaard Henriksen, Joseph Garrone, S V, Nicolas Beuchat, SigmaVX, Stephen Eckels, 9-lives, Renie Siqueira, Nick the Community Scientist, Jonah Dempcy and 4 moreReacted by dorjbatnasanjargalReacted by Morten N.O. Nørgaard Henriksen, SigmaVX, aviyi, charvar16, Ahmad Ibrahim Usman, Javad Afshar and Aelish Kumar@LukeNotable thanks, interesting finding - I'll convert #11764 to a draft for now - would be great if it's an issue in the webpack config not resolving main fields correctly ref config: https://webpack.js.org/configuration/resolve/#resolvemainfields - will try to replicate
287 remaining items
Load more actionsThe issue is tied to the version of react-scripts you are using. v5 has an issue as it excludes support for some node features and polyfills that were available in lower versions.
Your quick fix is to take react scripts down to v4 until a fix for v5 is in place unless you are comfortable with: 1) ejecting your app; 2) adding the webpack config changes that are needed.
https://web3auth.io/docs/troubleshooting/webpack-issues#react-create-react-app
that solved it, nothing further
Reacted by Marco Eckstein, Richard T. Miles, robothoustra, Drew Daniels, Soham Niyogi, Nora, Christof Jori, Matheus Caetano, Ronny Legones, Hawkeye Parker and 2 moreReacted by Quentin Nicolle, naazweb, Nora and Arul Georgehttps://web3auth.io/docs/troubleshooting/webpack-issues#react-create-react-app
that solved it, nothing further
Thanks Ebrahim ! After testing a lot of solutions, only this one wordked for me.
https://web3auth.io/docs/troubleshooting/webpack-issues#react-create-react-app
that solved it, nothing further
Solved it for me. Thanks @Ebrahim-Ramadan
Found another solution for the issue for folks who didn't like any of the above including me.
For example for
crypto,- Create a folder called
crypto - Create
package.jsonundercryptofolder and configure like this:{ "browser": "client.js", "main": "server.js", "types": "index.d.ts" // optional } - Create a file
crypto/client.js// crypto/client.js module.exports = window.crypto - Create a file
crypto/server.js(edited snippet according to @ljharb, thanks)// crypto/server.js module.exports = require("crypto").webcrypto
Now import
cryptofolder you just created. Hope it makes sense.- Create a folder called
@hoiekim those aren't the same APIs; you'd need
require('crypto').webcryptoto make them the same.Reacted by Hoie Kim and Devhttps://web3auth.io/docs/troubleshooting/webpack-issues#react-create-react-app
that solved it, nothing further
Wow that solved the issue! Thanks a lot Ebrahim!
hahhahahahahahaha ITS STILL OPEN!
Reacted by gizzye, Chris Frewin, Ken Ingram, Darrian and Ackermann YuriyReacted by ptmkenny and Younes BaddichReacted by Chaeun LeeThere is no immediate solution for this. A more dev friendly solution might be to provide an alternative version that does include the node packages, so we can avoid the complex "solutions" we have right now.
Reacted by Ken Ingramthis is crazy. CRAZY. but I can see this team is much like the flowjs team -- release a product into opensource but don't give a damn how it affects the clients when you make a breaking change with no reasonable way for current users to backout.
Reacted by Ken Ingram, Warren and Vlad DgUP
How not hate react
2025 still an issue
Just use node 20.19.4. That solved the issue for me
Reacted by Dev and Robert Brisita- added a commit that references this issue
on Dec 16, 2025
Describe the bug
Compiled with problems
Did you try recovering your dependencies?
Which terms did you search for in User Guide?
react-scripts 5 webpack Module not found: Error: Can't resolve 'fs'
Environment
npx create-react-app --info
Environment Info:
Steps to reproduce
In a project with react-scripts v5.0.0
Expected behavior
Actual behavior
Some useful comments: