pouchdb: PouchDB in Nextjs throws error
Issue
Whenever I try running my nextjs app using pouchDB (I am only using it on the server side and NOT on the client side) I get
Am I missing something?
Info
- Environment: (Nextjs (backend code Node.js))
- Platform: (Brave)
- Adapter: (leveldb)
- Server: (no server, I am working in local with in nextjs)
Reproduce
Initi a nextjs app. Setup pouchDB
import PouchDB from "pouchdb-node";
const db = new PouchDB("llmshare");
export default db;
use pouchDB in any API’s route.ts
import { NextResponse } from "next/server";
import db from "@/db/pouchDB";
export async function GET() {
try {
const res = await db.post({ title: "new code" });
return NextResponse.json({ id: res.id });
} catch (e) {
console.log({ e });
}
}
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 2
- Comments: 16 (5 by maintainers)
I also hit this issue attempting to add PouchDB to a NextJS application. This error (“No native build was found”) happens on build if using the
pouchbpackage, and if attempting to drop inpouchdb-browserinstead (as my intended use-case is all Client Components in NextJS), the buil error changes to “ReferenceError: self is not defined”. So neither of the PouchDB exports seem to play well with the NextJS server/client auto-detection.I’ve not encountered this error before with any other libraries, so unsure if this is something that PouchDB needs to fix, or NextJS?
I solved it by using next/dynamic and skipping ssr
Next.js - Skipping SSR
@spiritanand the error message suggests that the
leveldownversion doesn’t support Apple Silicon.Similar issues:
Upgrading pouchdb’s
leveldowndependency may fix this (https://github.com/Level/leveldown/issues/766).There are some open PRs attempting to do this:
I am facing the same issue, except I’m only using it on the client side, not the server side