'removing webpack from dependencies makes some parts of the web fail

I have a project that I just ported to use vitejs. After a couple of days bundling with vite I felt confident enogh to remove webpack. Interestingly, after removing webpack and some of it's companion libraries some parts of the app has stopped working. Specifically the parts of the app that load recharts.

My guess is that,for some reason, the webpack libraries had some deps that made that library work, and removing them makes it bundle differently.

Here is the commit where I remove them

And this is a screenshot:

enter image description here



Solution 1:[1]

I had a similar issue after migrating to Vite (I was using Recharts v4). I noticed the error occurred in a file importing the 'events' module - this allows you to use the Node events module in environments that don't have it (i.e. the browser). According to the readme for the 'events' package, Webpack includes the module for you by default:

You usually do not have to install events yourself! If your code runs in Node.js, events is built in. If your code runs in the browser, bundlers like browserify or webpack also include the events module.

I was able to fix the issue by installing the 'events' package (npm i events) so that my Recharts version had access to that module. I plan on upgrading to the next major Recharts version soon, which uses a different package for events. Hope this helped!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 haftav