Search code examples
angularwebpackiconv

Questionable iconv-lite dependency


Been working in an Angular project a couple of months with a very large bundle size, I've been trying to minimize the main bundle and lazy loading some routes. Using webpack-bundle-analyzer I've seen that a very large part of the bundle (g-zipped) is a package called iconv-lite that exists under encoding and I can't find what part of the app is using it.

Is it angular that is using it? Does anyone have an idea? I can see some things have dependencies to it in my yarn.lock like jest and less but those shouldn't be included in the main bundle.

Happy to get into some direction here.

enter image description here


Solution

  • After a lot of investigation, we found that it was a dependency called gettext-parser that was issue. gettext-parser was not meant for browsers. Webpack polyfilled the required node.js modules and one of them was body-parser and then in turn iconv-lite.

    We found this by updating to Angular 12 when webpack@5 stopped polyfilling node.js dependencies and it started to throw errors during the build.