Remove node polyfills in webpack
Webpack will currently, by default, add polyfills for various built-in node methods like setImmediate
, global
, fs
, Buffer
, etc. when they are detected in our source code. This is an old, vestigial behavior from a time before npm had a robust ecosystem of frontend-specific libraries and webpack aimed to offer its users the ability to use libraries meant for backend/nodejs in frontend contexts.
This can cause our code to get bloated without our knowledge or intention, and it can cause confusion about how certain polyfills found their way into our production code (ref: gitlab-ce#63534). It can also cause us to make poor decisions about using code clearly meant for backend use in frontend contexts (ref: gitlab-ce#30644).
Furthermore, this auto-polyfill feature for node will be removed in webpack 5. For gitlab-ce27312481, gitlab-ce3011693, and future maintainability reasons we ought to work toward disabling this feature.
Steps:
- Use
config.node = false
in ourwebpack.config.js
to disable these polyfills entirely. - Check the webpack output both before and after this change to identify all effected modules (any modules which explicitly or inadvertently relied on this behavior, likely including
sql.js
and others) - Identify and remedy any cases where this will break our code
- Commit any necessary changes, perhaps explicitly polyfilling some modules or flagging those which depend on them for removal.