Skip to content

Webpack 4 production build is missing dom4 polyfill #3333

@TheHolyWaffle

Description

@TheHolyWaffle

Environment

  • @blueprintjs/core 3.12.0
  • Windows 10 / Chrome 71

Steps to reproduce

  1. Do the following import:
    import { Position, Toaster, Intent } from "@blueprintjs/core";
  2. Make a production build using webpack 4
  3. Load and execute the page on IE11

Actual behavior

IE11 console errors: Object doesn't support property or method 'remove'

Expected behavior

No error should appear

Possible solution

It appears that the dom4 polyfill that includes the .remove() functionality is not included during the production build. This is because @blueprintjs/core is marked as sideEffect: false in package.json. Which means that webpack will cut away any unused imports/exports. Including the following lines which are responsible for loading in dom4:

if (typeof window !== "undefined" && typeof document !== "undefined") {
// we're in browser
// tslint:disable-next-line:no-var-requires
require("dom4"); // only import actual dom4 if we're in the browser (not server-compatible)
// we'll still need dom4 types for the TypeScript to compile, these are included in package.json
}

Solution is to mark this file as a sideEffect, see https://webpack.js.org/guides/tree-shaking/#mark-the-file-as-side-effect-free

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions