electron-userland / electron-userland/electron-webpack
Async bundles fail to load in prod builds
- Dominant language
- TypeScript
- Stars
- 902
- Forks
- 168
- PR merge metrics
- No merged PRs in 30d
Description
Came across electron-webpack the other day and gave it a spin. I haven't looked at Electron for a year or so, and it was a bit ugly back then, but this makes setting up a build incredibly smooth, thank you!
I have some dynamic imports (`import(filename)`) to async load some components in a React project:
- webpack is creating the `n.bundle.js` files correctly with `renderer.js`.
- `electron-webpack dev` works correctly
- `electron-webpack` build (prod) does not work.
- `renderer.js` loads, but `n.bundle.js` cannot be found.
- `app.asar` contains both `renderer.js` and `n.bundle.js`
This is on a Windows build (not sure about Linux/MacOS yet), using the default NSIS installer, and it seems to attempt loading `file:///C:/0.bundle.js` which fails with file not found. Sources tab shows the other files in `file:///C:/Users/tm/AppData/Local/Programs/james/resources/app.asar/renderer.js`.
I noticed the `app.asar.unpacked` folder only contains `node_modules/term-size` for whatever reason (probably a separate issue?), but unpacking `app.asar` manually shows `n.bundle.js` beside `renderer.js` where it should be.
So it seems like it's getting packaged correctly, but not loaded from the right path.
I'm using `import('./${container}.js')` ([seen here](https://github.com/james-proxy/james/blob/electron-webpack/src/renderer/containers/app.js#L9)), but I've also tried other paths, such as `@/containers/${container}.js` which didn't work either. I don't have a custom webpack config, just [`package.json` with a dll](https://github.com/james-proxy/james/blob/electron-webpack/package.json#L75).
This looks like a [`publicPath`](https://webpack.js.org/concepts/output/) issue. To test, I manually set `__webpack_public_path__` to the app.asar path (above) in my entry point, which works.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.