-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
v5 used to include polyfills for node.js core modules by default #11756
Comments
I have the same issue as well |
me too |
Webpack 5 no longer shims node builtin packages. Its a breaking change. |
I try to upgrade from v4.0.3 to 5.0.0 and It raise up the same error
|
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 |
My personal view: 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. |
Our two main usages are:
Our back-end compresses some of its data to optimize storage as well as network transfer. Our UI then uses zlib to uncompress it. |
Webpack 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? |
To toss in another example, the v5 upgrade showed me that the libraries for AWS Cognito use url:
If you were a direct user of webpack v4, upgrading to v5, you have a few options:
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? |
I've added a pr to gather feedback #11764 |
Same issue here. is there some documentation that we can follow for doing this migration? |
I'm not sure it's entirely a polyfill issue. I'm getting the |
@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 |
@zfarhad I had the same issue. Found out it was because I had Storybook as a dependency and it was using Webpack 4. Upgrading Storybook to use their new alpha version that supports Webpack 5 fixed me. So I would say, make sure none of your dependencies are using a conflicting version of webpack. |
@LukeNotable when importing 'handlebars/runtime' webpack seem to resolve correctly but if importing 'handlebars' it resolves to 'lib/index.js' ''' |
ERROR in Plugin "react" was conflicted between "package.json » eslint-config-react-app. |
Fwiw, seeing this for a package trying to use assert and stream-browserify. |
Webpack 5 and CRA v5 don't add fallbacks for nodejs modules any more, it's a breaking change - dotenv should not be added in the browser code related issues closed in dotenv repo Migration steps from v4 to v5: A: Go to the Npm or Github readme for the package you are trying to use and see if the package is meant to run in the browser
B: Search in the package Github issues for "browser" and include closed issues, please. Example for DotEnv repo
C: If the package should support the browser - then open an issue here in the CRA repo and we'll look into it - here to help! An example: @LukeNotable raised an issue - we've confirmed that as an issue, debugged and opened an issue in the Webpack repository.
We have opened an issue in Webpack webpack/webpack#15007 Sorry for the breaking change, but we are trying to keep you safe - we are considering better error message / documentation etc. Kind regards Morten |
Uh my guess is that this means a lot people can not upgrade to v5 for a long time. In example our own deps report 50 errors cause nodes assert ist used in various deps. |
"Then remove the package and find an alternative package better suited" is a great strategy when you have an unlimited budget, but in many cases these packages work just fine in the browser with a polyfill, and sometimes packages in the JS ecosystem go unmaintained and there aren't any good alternatives. If Webpack 5 has an option to include the polyfills, but CRA does not, are we just expected to immediately eject upon upgrading to edit the webpack config, or just stay on CRA 4? |
We need to make sure that we are fixing the root cause and not the symptom - like with the To repeat #11756 (comment) we a considering adding an escape hatch and document why not to use it #11764 Again - if you are using packages not meant for the browser - and the maintainers of those packages keep closing issues for browser support and state that the package is not meant for the browser, then it's likely a good idea to find another package that supports the browser. For more details on what nodejs builtin modules are see the nodejs api docs |
Works for me, although I needed some extra ones for http, https and zlib: "devDependencies": {
"buffer": "npm:buffer@^6.0.3",
"crypto": "npm:crypto-browserify@^3.12.0",
"http": "npm:stream-http@^3.2.0",
"https": "npm:https-browserify@^1.0.0",
"stream": "npm:stream-browserify@^3.0.0",
"util": "npm:util@^0.12.5",
"zlib": "npm:browserify-zlib@^0.2.0"
} Is the Update |
I happened to face this issue while using |
so CRA is effectively broken? And the dev team doesn't care? |
The cause of this issue is when you use a module that was meant for Node for the Browser. With Webpack 5, they stopped bundling backend modules for web. So, I think the only problem is that you're using a module that wasn't supported for web. I think in my case it was using |
@haneenmahd everything that with a working bundler that includes core module polyfills, supports the browser. webpack 5 simply decided to stop being a working node module bundler. |
Are your guys bosses living in a VR world already? How about you tell them to take off the goggles and fix this crap. |
for react-native errors: first install react-native-web and add
to your config-overrides.js |
I have the same issue with react-dev-utils: P.S. Adding the "url" directly to your own package.json will solve the problem. |
I think the salient point for any who come across this thread is that the React.js team no longer recommends CRA in the updated React docs. Here are the recommended frameworks for new react projects: Good luck! |
The 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 |
Thanks Ebrahim ! After testing a lot of solutions, only this one wordked for me. |
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
Now import |
@hoiekim those aren't the same APIs; you'd need |
Wow that solved the issue! Thanks a lot Ebrahim! |
hahhahahahahahaha ITS STILL OPEN! |
There 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. |
this 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. |
UP |
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:
The text was updated successfully, but these errors were encountered: