vercel/ai · error
Unsupported chunk type: ${_exhaustiveCheck}
Error message
Unsupported chunk type: ${_exhaustiveCheck} What it means
In stream-object.ts, a TransformStream switches over ObjectStreamPart types and throws this Error from the `default` branch when it encounters a part type it doesn't handle. The switch is exhaustive over the known union, so at runtime this indicates a stream part produced outside the expected type set — typically a package version mismatch or non-standard chunks injected into the stream.
Source
Thrown at packages/ai/src/generate-object/stream-object.ts:999
get partialObjectStream(): AsyncIterableStream<PARTIAL> {
return createAsyncIterableStream(
this.baseStream.pipeThrough(
new TransformStream<ObjectStreamPart<PARTIAL>, PARTIAL>({
transform(chunk, controller) {
switch (chunk.type) {
case 'object':
controller.enqueue(chunk.object);
break;
case 'text-delta':
case 'finish':
case 'error': // suppress error (use onError instead)
break;
default: {
const _exhaustiveCheck: never = chunk;
throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
}
}
},
}),
),
);
}
get elementStream(): ELEMENT_STREAM {
return this.outputStrategy.createElementStream(this.baseStream);
}
get textStream(): AsyncIterableStream<string> {
return createAsyncIterableStream(
this.baseStream.pipeThrough(
new TransformStream<ObjectStreamPart<PARTIAL>, string>({
transform(chunk, controller) {
switch (chunk.type) {View on GitHub (pinned to 69428b1f8b)
Solutions
- Reinstall dependencies and ensure a single `ai` version (`pnpm why ai`; dedupe).
- Rebuild the app after upgrades so stream producers and consumers share types.
- Remove custom patches that inject unknown parts; if it persists on a clean install, report a bug with the chunk type from the message.
Example fix
// before "ai": "^4.0.0" with a nested ai@3.4 in pnpm-lock.yaml // after rm -rf node_modules pnpm-lock.yaml && pnpm install "ai": "^4.3.16"
Defensive patterns
Strategy: fallback
Validate before calling
// detect version skew early
import { VERSION } from 'ai';
if (VERSION !== expectedAiVersion) console.warn('ai version mismatch:', VERSION); Type guard
function isUnsupportedChunkError(e: unknown): e is Error {
return e instanceof Error && e.message.startsWith('Unsupported chunk type');
} Try / catch
try {
for await (const part of result.partialObjectStream) { /* ... */ }
} catch (e) {
if (isUnsupportedChunkError(e)) {
console.error('SDK stream/type mismatch — reinstall dependencies');
// fallback: await result.object for the final value
} else throw e;
} Prevention
- Pin one version of `ai` across the workspace.
- Clean install and dedupe after every SDK upgrade.
- Avoid custom middleware that adds unknown stream parts.
- Report persistent occurrences with the chunk type from the message.
When it happens
Trigger: Mixed versions of `ai`/`@ai-sdk/*` in one app (stale lockfile, bundler duplication) so the stream emits a part the consumer doesn't know; custom provider/middleware emitting unknown chunk types; monkey-patched streams.
Common situations: After upgrading the AI SDK without reinstalling; monorepos resolving two copies of `ai`; experiments with custom stream transforms feeding streamObject internals.
Related errors
- Unsupported chunk type: ${_exhaustiveCheck}
- Unknown chunk type: ${exhaustiveCheck}
- 'element streams in no-schema mode' functionality not suppor
- 'element streams in object mode' functionality not supported
- 'element streams in enum mode' functionality not supported.
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/bec7b5218177bc04.
Report an issue: GitHub.