Skip to content

[2.x] [Webpack config] Code splitting fails for external npm modules #4601

@rafaucau

Description

@rafaucau

Current Behavior

When using dynamic imports for an external NPM module (e.g., import('sortablejs')), the generated chunk URL is incorrect. Flarum attempts to load the file from assets/forum/sortablejs.js instead of the extension's directory (e.g., assets/js/your-extension/forum/sortablejs.js), resulting in a 404 error.

Steps to Reproduce

  1. In a Flarum extension, dynamically import an external npm package (e.g., import('sortablejs')).
  2. Build the extension.
  3. Trigger the dynamic import in the browser.
  4. Check the network tab: Flarum tries to load assets/forum/sortable.js, which returns a 404.

Expected Behavior

Flarum should load the chunk from the extension's own assets directory (e.g., assets/js/your-extension/forum/sortablejs.js).

Screenshots

No response

Environment

  • Flarum version: 2.0.0-rc.1

Output of php flarum info

No response

Possible Solution

A workaround is to create a local wrapper file inside the extension's src/ directory (e.g., src/forum/wrapper.js containing import sortablejs from 'sortablejs'; export default sortablejs;) and import that local file instead.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions