Description
When I tried to deploy project based on the Convex NextJS template I got a TypeScript error in src/values/value.ts
around line 213:
./node_modules/convex/src/values/value.ts:213:7
Type error: Type 'ArrayBufferLike' is not assignable to type 'Value'.
Type 'SharedArrayBuffer' is not assignable to type 'Value'.
Type 'SharedArrayBuffer' is missing the following properties from type 'ArrayBuffer': resizable, resize, detached, transfer, transferToFixedLength
211 | throw new Error(`Malformed $bytes field on ${value as any}`);
212 | }
> 213 | return Base64.toByteArray(value.$bytes).buffer;
| ^
214 | }
215 | if (key === "$integer") {
216 | if (typeof value.$integer !== "string") {
Next.js build worker exited with code: 1 and signal: null
From here on is Copilot's explanation and suggested fix:
This error is occurring because recent TypeScript versions have expanded the ArrayBuffer
interface with new properties (resizable
, resize
, detached
, transfer
, etc.) that are not present in SharedArrayBuffer
.
Both ArrayBuffer
and SharedArrayBuffer
implement the ArrayBufferLike
interface, but when code treats an ArrayBufferLike
as a Value
, it fails because SharedArrayBuffer
is missing the properties that Value
expects.
Suggested Fix
The fix would involve checking specifically for ArrayBuffer
rather than using the more general ArrayBufferLike
type. Based on the error location, the issue is likely in an isValue
or similar validation function.
Here's a suggested change (line numbers approximate):
// Current problematic code (around line 213)
// Likely something like:
if (value instanceof ArrayBufferLike) {
// Code that assumes value has ArrayBuffer properties
return true;
}
// Suggested fix:
if (value instanceof ArrayBuffer) { // Specifically check for ArrayBuffer, not ArrayBufferLike
// Code that uses ArrayBuffer properties
return true;
}
// Optionally add separate handling for SharedArrayBuffer if needed:
if (typeof SharedArrayBuffer !== "undefined" && value instanceof SharedArrayBuffer) {
// Handle SharedArrayBuffer differently
return false; // or custom handling as appropriate
}
Alternatively, if SharedArrayBuffer
should be supported as a valid Value
type, the Value
type definition would need to be updated to accommodate the differences between ArrayBuffer
and SharedArrayBuffer
.
Environment
- TypeScript version: 5.8.3
- convex-js version: 1.24.1