{
  "$type": "site.standard.document",
  "canonicalUrl": "https://johnnyreilly.com/posts/ts-loader-goes-webpack-4-again",
  "description": "TypeScript webpack loader `ts-loader@9.6+` now supports webpack 4.",
  "path": "/posts/ts-loader-goes-webpack-4-again",
  "publishedAt": "2026-05-30T00:00:00.000Z",
  "site": "at://did:plc:yy3apqjlms24kso7ahn7lbmb/site.standard.publication/3mova7c4nho2b",
  "tags": [
    "webpack",
    "ts-loader",
    "typescript"
  ],
  "textContent": "Back in 2021 I published a post called _ts-loader goes webpack 5_; a big exciting post about how ts-loader was upgraded to directly support webpack 5, and drop support for webpack 4 in v9 of ts-loader.\n\nFor reasons which I'll get into shortly, as of v9.6.0, ts-loader now supports both webpack 5 (as it did already) and webpack 4. So if you're a webpack 4 user, you can now use ts-loader@9, rather than using ts-loader@8.\n\n\n\nWhy support webpack 4 again?\n\nIt is 2026. ts-loader@9 was released in 2021. I made the (bold) decision then to drop support for webpack 4 there and then. I would maintain webpack 4 branch in ts-loader so I could make any patches that might be necessary over time.\n\nAt the time this seemed reasonable; webpack had been evolving quickly. I remember the path from webpack 1 to webpack 4 being pretty swift and figured that would continue. However, five years have passed and webpack 5 is the latest version of webpack still. (That may change.) After webpack 5 shipping, it took people a very long time to make the migration across from 4 to 5. A very, very long time.\n\nTake a look at this screenshot of webpack major version usage on npmx:\n\nWhilst you might be thinking \"wow - people really are using webpack 5!\", what you should also be thinking is \"wow - webpack 4 still has 4 million downloads a week!\" As we can see, webpack 4 has not gone away, and is probably not going to any time soon.\n\nLikewise if you look at the major version usage for ts-loader you'll see this:\n\nJust as webpack 4 is getting around 4 million downloads a week, ts-loader@8 is getting just under 1 million downloads a week. (Where these are coming from is a mystery to me BTW - personally I'm using Vite for most of my projects - but let me not digress.)\n\nOccasionally I've found myself patching ts-loader@8 for the webpack 4 users (often with community help). The TypeScript 6 release contained a change that lead me to patching ts-loader@9. The TypeScript 6 patch shipped as part of ts-loader@9.5.7. Sure enough though, there are also webpack 4 users out there who would like to use TypeScript 6. A PR was raised against ts-loader to backport the patch to ts-loader@8: https://github.com/TypeStrong/ts-loader/pull/1695\n\nSince I last patched ts-loader@8, we've migrated to npm Trusted Publishing. It's a little fiddly, but ts-loader@9 is on that train. We could port that to ts-loader@8 as well, but I found myself wondering this: why not just support webpack 4 on ts-loader@9 instead?\n\nLet the experiment begin!\n\nSo I decided to experiment adding webpack 4 support back. I didn't want to do do it by hand, so I threw GitHub Copilot at the problem:\n\nI was pretty sure that this could be achieved without masses of code changes and without impacting performance. If that wasn't the case, I wouldn't bother.\n\nCopilot zigged and zagged a bit, but it did build a version of ts-loader that supported both webpack 4 and 5, and the changes required were not extensive. It did make a few odd choices which I amended. But all in all, a solid job.\n\nAs an aside, I did give Claude a few runs at this too, but he seemed to be having an off day - we all have those I guess.\n\nThe changes required generally came down to:\n\n- different APIs in webpack 4 as compared to webpack 5\n- options in webpack 4 require usage of a dedicated library called loader-utils. This is a dependency of webpack 4, and so we've added it to the peerDependencies of ts-loader and marked it as optional (since it won't be used for webpack 5)\n- the execution test pack in ts-loader now supports both webpack 4 and webpack 5. We're not going to bother with the comparison test pack for now.\n\nI also upgraded ESLint whilst I was there, and that lead to some general tidy ups. You can see the PR where this all happened here: https://github.com/TypeStrong/ts-loader/pull/1697\n\nts-loader@9.6.0 supports webpack 4\n\nAfter mulling for a little while, we decided to ship, and Ashley Claymore released 9.6.0. So if you're using webpack 4, you should now be able to use ts-loader@9.\n\nFor me, this hopefully means an end to supporting webpack 4 via the dedicated branch, which should make my life easier. I'm not quite sure what will happen to ts-loader when TypeScript 7 lands, but if there's work to do on ts-loader, ideally it only needs to be done in one place.\n\nDon't take this change as confirmation that ts-loader is going get support back for webpacks 3, 2 or 1 as well. It will not! But hopefully it should ease maintainers lives.",
  "title": "ts-loader goes webpack 4... again!"
}