Normally, we don't need to use Node libs on the browser side. However, it is possible to use some Node libs when the code will run on both the Node side and the browser side, and Node Polyfill provides browser versions of polyfills for these Node libs.
By using the Node Polyfill plugin, Node core libs polyfills are automatically injected into the browser-side, allowing you to use these modules on the browser side with confidence.
You can install the plugin using the following command:
You can register the plugin in the rsbuild.config.ts file:
BufferprocessWhen the above global variables are used directly in code, the corresponding polyfill will be injected.
assertbufferconsoleconstantscryptodomaineventshttphttpsospathpunycodeprocessquerystringstream_stream_duplex_stream_passthrough_stream_readable_stream_transform_stream_writablestring_decodersystimersttyurlutilvmzlibWhen the above module is referenced in code via import / require syntax, the corresponding polyfill will be injected.
child_processclusterdgramdnsfsmodulenetreadlinerepltlsCurrently there is no polyfill for the above modules on the browser side, so when you import the above modules, it will automatically fallback to an empty object.