Skip to content

Fix #8558: added ESM builds to fix 'require is not defined' via jsDelivr +esm - #8559

Merged
wenzhixin merged 1 commit into
developfrom
new/issue-8558-esm-fix
Nov 5, 2026
Merged

wenzhixin merged 1 commit into
developfrom
new/issue-8558-esm-fix

Conversation

@wenzhixin

@wenzhixin wenzhixin commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

**🤔Type of Request

  • Bug fix
  • New feature
  • Improvement
  • Documentation
  • Other

🔗Resolves an issue?
Fix #8558

📝Changelog

  • Core

  • Extensions

  • Update: Added ESM builds (.esm.js / .esm.min.js) and a module field in package.json to fix require is not defined when the package is consumed via jsDelivr's +esm endpoint (e.g. Symfony AssetMapper importmap).

💡Example(s)?
Not applicable — no API/behavior change from the user side. Before/after of the jsDelivr +esm output:

Before (UMD entry converted, bare require throws in browser):

bootstrap-table.index-*.js:7 Uncaught ReferenceError: require is not defined

After (ESM entry used directly):

import $ from "jquery"   // top-level import, resolved by the ESM pipeline

☑️Self Check before Merge
⚠️ Please check all items below before reviewing. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Changelog is provided or not needed
Root cause & verification details

The npm package ships UMD-only entries (main: dist/bootstrap-table.min.js). When jsDelivr's +esm service converts the UMD file, the require("jquery") inside the UMD conditional (typeof exports === 'object' ? ... require('jquery') ...) cannot be statically detected and rewritten. The converted module keeps a bare require call, and since jquery is a peerDependency no import shim is injected for it — the browser then throws when the CJS branch is activated by the jsDelivr wrapper. Older versions re-converted through the current jsDelivr pipeline fail the same way; 1.28.0 just surfaced it.

Solution:

  • Add an es format output for every rollup entry (core, extensions, themes, locales) → .esm.js / .esm.min.js files with a top-level import $ from 'jquery' that any ESM pipeline can resolve and rewrite correctly.
  • Add "module": "dist/bootstrap-table.esm.min.js" to package.json so ESM-aware resolvers (jsDelivr +esm, bundlers) pick the real ESM build instead of converting the UMD one.
  • Inject jQuery: 'jquery' alongside $ in the rollup inject() plugin, so the bare jQuery identifier used in the search module resolves to the imported jquery instance instead of an implicit global (window.jQuery) — without a global jQuery, typing in the search field previously threw ReferenceError in ESM consumers.
  • dist/ artifacts are rebuilt at release time (per repo convention, they are not part of feature PRs).

Verification (built locally, artifacts not committed):

  • dist/bootstrap-table.esm.min.js starts with import t from"jquery", exports BootstrapTable as default, no UMD wrapper / no bare require
  • All 25 extension ESM builds import jquery as a top-level ESM import
  • No bare instanceof jQuery remains in any ESM output (rewritten to the imported $ binding); UMD output unchanged semantically
  • Module load smoke-tested under happy-dom (VERSION: 1.28.0, DEFAULTS present)
  • npm run test:vitest: 489 tests passed

@wenzhixin
wenzhixin force-pushed the new/issue-8558-esm-fix branch from 209c985 to d633aeb Compare November 4, 2026 10:54
@wenzhixin wenzhixin changed the title fix: add ESM builds to fix 'require is not defined' via jsDelivr +esm Fix #8558: added ESM builds to fix 'require is not defined' via jsDelivr +esm Nov 4, 2026
@wenzhixin
wenzhixin requested a balanced review from Copilot November 4, 2026 14:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The ESM build injects only $, leaving search code dependent on a global jQuery and causing a ReferenceError when that global is absent.

1 open issue
What changed in this PR

Adds native ESM builds to address the require is not defined error reported in #8558 when Bootstrap Table is loaded through jsDelivr’s +esm endpoint.

Changes:

  • Generates ESM outputs alongside existing UMD builds for core, extensions, themes, and locales.
  • Adds a package module entry pointing ESM-aware consumers to the minified ESM build.
  • Corrects filename replacement patterns to match literal .js suffixes.
File Description
rollup.config.js Adds ESM outputs for development and production builds while retaining UMD outputs.
package.json Declares the minified ESM bundle through the module field.

Review effort: Balanced

Comment thread rollup.config.js Resolved
…ivr +esm

- Add an 'es' format output for every rollup entry (core, extensions,
  themes, locales), producing .esm.js / .esm.min.js files with a
  top-level 'import $ from "jquery"' that ESM pipelines can resolve
- Add 'module' field to package.json so ESM-aware resolvers (jsDelivr
  +esm, bundlers) pick the ESM build instead of converting the UMD one

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the changes adding native ESM builds alongside existing UMD builds.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@wenzhixin
wenzhixin merged commit e72cf8e into develop Nov 5, 2026
3 checks passed
@wenzhixin
wenzhixin deleted the new/issue-8558-esm-fix branch November 5, 2026 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bootstrap-table.index-Bx4d3Te.js:7 Uncaught ReferenceError: require is not defined

2 participants