Skip to content

[2.x] fix(webpack): prevent Uncaught ReferenceError for async default exports#4397

Merged
imorland merged 3 commits intoflarum:2.xfrom
rafaucau:fix/async-default-export
Mar 5, 2026
Merged

[2.x] fix(webpack): prevent Uncaught ReferenceError for async default exports#4397
imorland merged 3 commits intoflarum:2.xfrom
rafaucau:fix/async-default-export

Conversation

@rafaucau
Copy link
Contributor

@rafaucau rafaucau commented Mar 3, 2026

image

Changes proposed in this pull request:

  • autoExportLoader.cjs: Fixed a regex bug that incorrectly captured the async keyword as an export name when using anonymous arrow functions (e.g., export default async () => {}). This prevents the Uncaught ReferenceError: async is not defined runtime error in extensions.
  • babel.config.cjs: Dynamically set useESModules based on process.env.NODE_ENV === 'test'. This fixes the Jest test suite which was failing due to ESM imports being injected into the CommonJS test environment.
  • Added tests for both named and anonymous async exports.

Necessity

  • Has the problem that is being solved here been clearly explained?
  • If applicable, have various options for solving this problem been considered?
  • For core PRs, does this need to be in core, or could it be in an extension?
  • Are we willing to maintain this for years / potentially forever?

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Core developer confirmed locally this works as intended.
  • Tests have been added, or are not appropriate here.

@rafaucau rafaucau requested a review from a team as a code owner March 3, 2026 02:07
@rafaucau rafaucau changed the title [2.x] fix(webpack): prevent Uncaught ReferenceError for async anonymous default exports [2.x] fix(webpack): prevent Uncaught ReferenceError for async anonymous default exports Mar 3, 2026
@rafaucau rafaucau changed the title [2.x] fix(webpack): prevent Uncaught ReferenceError for async anonymous default exports [2.x] fix(webpack): prevent Uncaught ReferenceError for async default exports Mar 3, 2026
@imorland imorland added this to the 2.0.0-beta.8 milestone Mar 5, 2026
Copy link
Member

@imorland imorland left a comment

Choose a reason for hiding this comment

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

Thank you @rafaucau this is a much needed fix!

@imorland imorland merged commit d3b4638 into flarum:2.x Mar 5, 2026
28 checks passed
rafaucau added a commit to android-com-pl/flarum-lscache that referenced this pull request Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants