OiO.lk Blog javascript Webpack: Pre-compiled Library's async chunks can't be resolved properly in a separate compiled App
javascript

Webpack: Pre-compiled Library's async chunks can't be resolved properly in a separate compiled App


Problem

  1. I have a local Library that uses async imports. This Library eventually compiled to a bundle that contains entry point and async chunks. When run the compiled Library the entry point requests the async chunks (typical webpack case).
  2. This pre-compiled Lib then imported and used in a separate local App. When the App also gets compiled, it can’t properly resolve the paths to the Lib’s async chunks. The Lib’s entry point though resolves correctly and is included to the App’s final bundle, but once the Lib’s entry point requests for the Lib’s async chunks it can’t find them (because pre-compiled chunk paths became incorrect relatively to the App bundle).

Sidenotes

  1. It all happens inside monorepo
  2. The App does need to import pre-compiled version of the Lib (don’t ask me why, I intentionally omitted the details, because it’s too long to explain)
  3. Dynamic imports inside the Lib (that trigger creating async chunks in the bundle) can not be avoided.

Question

Is there a way I could tweak the webpack config (on the Lib side), so it always properly resolves async chunk paths, no matter where this bundle is imported in.

Already tried

  • Setting webpack.config.output.publicPath to either 'auto', '' or './'



You need to sign in to view this answers

Exit mobile version