Skip to content

[FIX] Bundler: Improve error ESM handling#1203

Merged
matz3 merged 3 commits intov4from
v4-lbt-improvements
Apr 20, 2026
Merged

[FIX] Bundler: Improve error ESM handling#1203
matz3 merged 3 commits intov4from
v4-lbt-improvements

Conversation

@matz3
Copy link
Copy Markdown
Member

@matz3 matz3 commented Apr 2, 2026

  • [FIX] Bundler: Reduce noise from ESM parse errors
  • [FIX] Bundler: Skip ESM modules during bundling and log errors
  • [FIX] Bundler: Also detect import.meta as ESM indicator

See commit messages for details.

@matz3 matz3 requested a review from a team April 2, 2026 14:25
@matz3 matz3 changed the title [FIX] Bundler: Improve ESM handling [FIX] Bundler: Improve error ESM handling Apr 2, 2026
d3xter666
d3xter666 previously approved these changes Apr 3, 2026
@matz3 matz3 requested a review from codeworrior April 7, 2026 07:07
Comment thread lib/lbt/resources/ResourcePool.js Outdated
Comment thread lib/lbt/bundle/Builder.js Outdated
matz3 added 3 commits April 16, 2026 17:50
Change the log level for JS parse failures in determineDependencyInfo
from error to verbose. These parse errors occur frequently when a
library contains third-party ESM code (using import/export), which the
LBT bundler does not support. Since these modules are typically not
included in custom bundles, logging at error level creates unnecessary
noise for users.

Errors during actual bundling (e.g. writePreloadModule) are still
reported at the appropriate level.
ESM modules (using import/export) cannot be bundled with the
LBT bundler. Previously, including an ESM module in a preload
section caused the bundle to contain a literal "undefined" string
due to rewriteDefine() returning {} instead of null on parse error.

- Add Format.ESM to ModuleInfo and detect ESM in ResourcePool
  during dependency analysis
- Filter out ESM modules during bundle resolution in Resolver,
  so they are excluded from all section types
- Exclude ESM modules from bundle subModule metadata
- Fix rewriteDefine() to return null on parse error (safety fix)
Modules using import.meta (e.g. import.meta.url, import.meta.resolve)
were not detected as ESM because only the 'import'/'export' parse error
was checked. Now also handle the 'Cannot use import.meta outside a
module' error from espree.
@matz3 matz3 force-pushed the v4-lbt-improvements branch from ce81d7b to eae8847 Compare April 16, 2026 16:01
@matz3 matz3 requested a review from RandomByte April 17, 2026 09:04
@matz3 matz3 merged commit 58013d5 into v4 Apr 20, 2026
20 checks passed
@matz3 matz3 deleted the v4-lbt-improvements branch April 20, 2026 08:04
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.

3 participants