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 image

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)

Most upvoted comments

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 pouchb package, and if attempting to drop in pouchdb-browser instead (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

import React from 'react';
import dynamic from "next/dynamic"

const ComponentWithPouch = dynamic(() => import("@/components/ComponentWithPouch "), {
  ssr: false,
})

export default function Page(): ReactElement {
  return (
    <>
      <ComponentWithPouch />
    <>
  )
}

@spiritanand the error message suggests that the leveldown version doesn’t support Apple Silicon.

Similar issues:

Upgrading pouchdb’s leveldown dependency 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

- error node_modules/node-gyp-build/index.js (56:0) @ load.path
- error Error: No native build was found for platform=linux arch=x64 runtime=node abi=108 uv=1 libc=glibc
    at __webpack_require__ (/media/gizmoclardin/Yashvardhan/Work/covalent/goldrush/.next/server/webpack-runtime.js:33:43)
    at __webpack_require__ (/media/gizmoclardin/Yashvardhan/Work/covalent/goldrush/.next/server/webpack-runtime.js:33:43)
    at __webpack_require__ (/media/gizmoclardin/Yashvardhan/Work/covalent/goldrush/.next/server/webpack-runtime.js:33:43)
    at __webpack_require__ (/media/gizmoclardin/Yashvardhan/Work/covalent/goldrush/.next/server/webpack-runtime.js:33:43)
    at eval (./utils/services/pouch.ts:6:65)
    at (ssr)/./utils/services/pouch.ts (/media/gizmoclardin/Yashvardhan/Work/covalent/goldrush/.next/server/app/tx/[tx_hash]/page.js:12178:1)
    at __webpack_require__ (/media/gizmoclardin/Yashvardhan/Work/covalent/goldrush/.next/server/webpack-runtime.js:33:43)
    at eval (./components/shared/addresses-layout/addresses-layout.tsx:20:79)
    at (ssr)/./components/shared/addresses-layout/addresses-layout.tsx (/media/gizmoclardin/Yashvardhan/Work/covalent/goldrush/.next/server/app/tx/[tx_hash]/page.js:10671:1)
    at __webpack_require__ (/media/gizmoclardin/Yashvardhan/Work/covalent/goldrush/.next/server/webpack-runtime.js:33:43)
    at eval (./components/shared/addresses-layout/index.tsx:6:75)
    at (ssr)/./components/shared/addresses-layout/index.tsx (/media/gizmoclardin/Yashvardhan/Work/covalent/goldrush/.next/server/app/tx/[tx_hash]/page.js:10704:1)
    at __webpack_require__ (/media/gizmoclardin/Yashvardhan/Work/covalent/goldrush/.next/server/webpack-runtime.js:33:43)
    at eval (./components/shared/index.tsx:13:75)
    at (ssr)/./components/shared/index.tsx (/media/gizmoclardin/Yashvardhan/Work/covalent/goldrush/.next/server/app/tx/[tx_hash]/page.js:11001:1)
    at __webpack_require__ (/media/gizmoclardin/Yashvardhan/Work/covalent/goldrush/.next/server/webpack-runtime.js:33:43)
    at eval (./components/tx/tx.tsx:17:76)
    at (ssr)/./components/tx/tx.tsx (/media/gizmoclardin/Yashvardhan/Work/covalent/goldrush/.next/server/app/tx/[tx_hash]/page.js:11287:1)
    at __webpack_require__ (/media/gizmoclardin/Yashvardhan/Work/covalent/goldrush/.next/server/webpack-runtime.js:33:43)
    ```