Skip to content

fix(vanilla): wrap bundles in IIFE to avoid duplicate global __webpack_exports__ #55

Open

Description

@Hug0-Drelon

Summary

Vanilla JS bundles from getVanillaConfig() set output.iife: false, so each file emits a top-level let __webpack_exports__ in global scope. When two or more such bundles load on the same WordPress admin page, Safari throws:

SyntaxError: Can't create duplicate variable: '__webpack_exports__'

Reactified builds (getReactifiedConfig()) are unaffected — they are wrapped in an IIFE.

Steps to reproduce

  1. Build a Polylang consumer (e.g. Polylang Pro) with npm run dev.
  2. Open an admin screen that enqueues multiple vanilla scripts (e.g. posts list → pll_admin + pll_post, or media library → pll_admin + pll_media).
  3. Check the browser console.

Suggested fix

Set iife: true in transformJsEntry() (and in createBundledJsConfig() if present):

output: {
  // ...
  iife: true,
},

Vanilla scripts are standalone WordPress enqueues with no global library export, so scoping webpack internals should not change runtime behaviour.

Acceptance Tests

  • npm test in polylang-build-scripts
  • Polylang Pro builds and loads without console errors on admin screens with 2+ vanilla scripts
  • Smoke-test: languages settings, widgets, classic editor, bulk translate
  • Reactified bundles (editors/site.js, block-editor.js) unchanged

Environment

  • @wpsyntex/polylang-build-scripts 2.4.0, webpack 5.x
  • Consumer: Polylang Pro 3.9-beta2
  • Reproducible with SCRIPT_DEBUG on or off (.js and .min.js)

Activity

  1. added theissue type on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions