Service worker build ignores vite build.target and esbuild options
### Describe the bug
`build_service_worker()` runs a separate `vite.build()` with `configFile: false`. It forwards `define` and `build.minify` from the main Vite config, but not `build.target` or `esbuild`.
As a result, user overrides in `vite.config.js` (e.g. `build.target: "es2022"`, `esbuild.supported.destructuring`) apply to the main client build but not to the service worker build.
With `esbuild@0.28.x` this causes the service worker build to fail (https://github.com/evanw/esbuild/issues/4436):
```
[vite:esbuild-transpile] Transform failed with N errors: service-worker.mjs:158:10: ERROR: Transforming destructuring to the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides) is not supported yet
```
### Reproduction
1. Open https://stackblitz.com/edit/service-worker-build-error?file=package.json
2. Run `npm run build`
### Logs
```Shell
```
### System Info
```Shell
System:
OS: Linux 7.0 Fedora Linux 44 (KDE Plasma Desktop Edition)
CPU: (12) x64 AMD Ryzen 5 7500F 6-Core Processor
Memory: 15.52 GB / 31.05 GB
Container: Yes
Shell: 5.9 - /usr/bin/zsh
Binaries:
Node: 24.14.0 - /home/envyvox/.local/share/pnpm/node
Yarn: 1.22.22 - /usr/local/bin/yarn
npm: 11.9.0 - /home/envyvox/.local/share/pnpm/npm
pnpm: 10.32.1 - /home/envyvox/.local/share/pnpm/pnpm
Browsers:
Chrome: 149.0.7827.53
Firefox: 151.0.3
Firefox Developer Edition: 151.0.3
npmPackages:
@sveltejs/adapter-node: 5.4.0 => 5.4.0
@sveltejs/kit: 2.57.1 => 2.57.1
@sveltejs/mcp: 0.1.20 => 0.1.20
@sveltejs/vite-plugin-svelte: 6.1.4 => 6.1.4
svelte: 5.55.5 => 5.55.5
vite: 6.4.2 => 6.4.2
```
### Severity
serious, but I can work around it
### Additional Information
_No response_
关闭于 2026-06-17 4 条评论