Project

General

Profile

Bug #28863

webpack tree-shaking removes necessary code from the bundle

Added by Avi Sharvit 9 months ago. Updated 9 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
JavaScript stack
Target version:
Difficulty:
Triaged:
No
Bugzilla link:
Fixed in Releases:
Found in Releases:

Description

The default handling of js modules changed from transpiling them to commonjs in babel 6 to keeping them as es6 modules in babel 7.
Webpack 3 knows how to tree-shake (i.e. remove unused code) es6 modules, but not commonjs modules.
The unfortunate outcome for us here is that all functions that weren’t used by core got removed from the core bundle when foreman gets built. This includes, in this case, propsToSnakeCase which was only used by katello and not in core. However, when katello gets built, these functions don’t get tree-shaken out, resulting in katello js code expecting the function to be available in the core bundle (using a very descriptive name such as W.e). However, since the missing function was removed, the uglification resulted in a different function being assigned to W.e, meaning that when katello tries to call it, it actually triggers a different function, in this case translateObject, which obviously fails as it is used for something completely different.

Associated revisions

Revision 25082584 (diff)
Added by Avi Sharvit 9 months ago

Fixes #28863 - upgrade tfm-builder to v4.0.7

In order to prevent webpack to do tree-shaking,
tfm-builder v4.0.7 set modules to commonjs.

History

#1 Updated by The Foreman Bot 9 months ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/7393 added

#2 Updated by The Foreman Bot 9 months ago

  • Fixed in Releases 2.0.0 added

#3 Updated by Avi Sharvit 9 months ago

  • Status changed from Ready For Testing to Closed

Also available in: Atom PDF