[2.x] [Webpack config] Code splitting fails for external npm modules
- Dominant language
- PHP
- Stars
- 6.7k
- Forks
- 883
- Avg merge
- 15h 16m
- Merged PRs (30d)
- 73
Description
### 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_
Contributor guide
Assessment
This issue has not been assessed yet.