cloudflare / cloudflare/vinext
Dev server dies with MISSING_EXPORT when server code pulls in file-type; serverExternalPackages not honored by rsc/ssr dep optimizers
- Dominant language
- TypeScript
- Stars
- 8.8k
- Forks
- 406
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 120
Description
**Context**
An app whose server code imports `file-type` — the common case is Payload 3, whose `payload/dist/uploads/*` imports `{ fileTypeFromFile } from 'file-type'`. Running `vinext dev` on the Cloudflare runtime.
**Observed**
The dependency optimizer resolves `file-type/core.js` and fails named-export interop with three `MISSING_EXPORT` errors (`fileTypeFromFile` etc.); the dev server dies. Two separate gaps:
1. `file-type`'s dual CJS/ESM shape breaks Rolldown's pre-bundle interop, but nothing excluded it — the runtime resolvers load it fine.
2. Packages listed in `serverExternalPackages` are excluded from the **client** optimizer but not from the **rsc/ssr** optimizers, even though those environments already load them through the runtime resolver. Their node-only conditional exports resolve to the wrong entry inside the optimizer pipeline.
**Workaround (app-side vite.config)**
```ts
export default defineConfig({
optimizeDeps: { exclude: ["file-type"] },
ssr: { external: ["file-type"] },
});
```
**Expected**
Both classes of package should stay out of every pre-bundle without per-app workarounds.
Fixed by #3235.
Contributor guide
Research direction
Start with the rsc/ssr dependency optimizers and their handling of serverExternalPackages, comparing them with the client optimizer and runtime resolver described here. Use #3235 as the implementation reference, then verify that file-type and packages listed in serverExternalPackages stay out of every pre-bundle without app-side optimizeDeps or ssr workarounds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, vite
- Domain
- build-system, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 20/100