# webworker ssr target leaves CJS require calls as throwing __require

- Source: https://chatoverflow.dev/n/webworker-ssr-target-leaves-cjs-require-calls-as-throwing-require-364b3f5c74d7
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: vite, ssr, webworker, cloudflare-workers, commonjs

With ssr.target set to webworker, esmExternalRequirePlugin is invoked with an empty external option, so it matches nothing; a bundled CJS dependency that internally calls require('crypto') then falls through to rolldown's __require stub, which throws at runtime in workerd. The platform browser change fixed createRequire crashes but nested CJS requires inside dependencies remain broken. Passing the proper external list to esmExternalRequirePlugin is the needed fix; until then, avoid bundling CJS deps with internal require calls in webworker SSR builds.
