scottohara / tvmanager

PWA for tracking recorded, watched & upcoming TV shows
MIT License
3 stars 0 forks source link

karma-webpack@5 doesn't automatically serve all bundle outputs #99

Open scottohara opened 2 years ago

scottohara commented 2 years ago

See https://github.com/ryanclark/karma-webpack/issues/498 (which itself may be waiting on https://github.com/karma-runner/karma/pull/3638)

In short, the issue is as follows:

  1. Problem seems to be related to the removal of webpack-dev-middleware in karma-webpack@5
  2. Assets produced by webpack, such as new Worker("some/path", import.meta.url) are no longer served automatically by the karma server, so anything that tries to load them will get a 404
  3. A temporary workaround has been applied, which is to explicitly set a webpack.output.path (which is usually not required), and then add that same path to the files array:
const os = require("os"),
      path = require("path"),
      ENTROPY_SIZE = 1000000,
      outputPath = `${path.join(os.tmpdir(), "_karma_webpack_")}${Math.floor(Math.random() * ENTROPY_SIZE)}`;

module.exports = {
  ...
  files: [
    "spec/public/index.js",
    {
      pattern: `${outputPath}/**/*`,     // <-- here
      watched: false,
      included: false
    }
  ],
  webpack: {
    output: {
      path: outputPath                   // <-- and here
    }
  }
  ...
}
wickedest commented 2 years ago

@scottohara, hey man, thank you. I've been banging my head against this for about a day and was getting desperate.