In next js I am getting this error in the image
queries: [
Query.equal('title', TitleId),
Query.limit(10)
]
am I doing something wrong ? appwrite version: 22.0.0 and I found a diy workaround for now
const SafeQuery = {
limit: (value) => JSON.stringify({ method: "limit", values: [value] }),
equal: (attribute, value) =>
JSON.stringify({ method: "equal", attribute, values: [value] }),
};
queries: [SafeQuery.equal("titleId", titleId), SafeQuery.limit(1)],
I dont know why is this happening.
I got a debug from antigravity
It was a bit of both—a conflict between the Appwrite SDK and the Next.js build environment (specifically when using Turbopack ).
Here is the breakdown of why it failed:
- The SDK Dependency
The Appwrite Web SDK uses a library called
json-bigintinternally. This library is used to safely convert query objects (like Query.limit(10)) into JSON strings while ensuring large numbers (BigInts) don't lose precision. - The Failing Check
Inside that
json-bigintlibrary, there is a technical check that looks like this:
if (value instanceof BigNumber) { ... }
This check is designed to see if a value is a high-precision number.
- The "Causal" Conflict In the Next.js environment (specifically the way it bundles modules), the BigNumber constructor was not being correctly identified as a "callable function" by the time it reached that specific line in the SDK.
When JavaScript sees x instanceof Y, it expects Y to be a constructor (a class or function). Because of a module resolution glitch during the build process, BigNumber was essentially "empty" or not recognized as a function, which triggered the error:
TypeError: Right-hand side of `instanceof` is not callable
Why the Fix Works
The SafeQuery helper I wrote simply skips the SDK's broken stringification logic. Instead of giving the SDK an object and asking it to stringify it (which triggers the crash), we give it the exact JSON string it expects:
// Instead of Query.limit(10) returning an object...
// SafeQuery returns the final string directly:
'{"method":"limit","values":[10]}'
By providing the final product directly, we bypassed the line of code in the SDK that was crashing. This is a common workaround for SDK-level bundling issues in modern frameworks like Next.js.
Hey, thanks for sharing, I just communicated this to the team!
tagging <@743532656767270934> as well
interesting, thanks for this detailed analysis. helps a lot! <:appwritepeepo:1156975874852270110>
i will be working on workaround for this
When will the fixed sdk.be released?
few minutes 😄
[SOLVED] Weird Query Error
Recommended threads
- sh: vite: Permission denied
When installing the vue starter template as site and then adding DaisyUI, i get the error `sh: vite: Permission denied`. I also got this issue (with a fresh tem...
- Appwrite Auth & Function don't reveal cl...
When I execute a function or sign in with my Flutter app, Appwrite does not show my real IP: instead, it seems that Appwrite shows Fastly CDN IP address.
- All function deployments fail (node 18-2...
Error: bash: /usr/local/server/helpers/build-cache.sh: No such file or directory Sidecar error: Build archive was not created at /mnt/code/code.tar.gz Scope: ...