holdenH
Convex Community3y ago
7 replies
holden

Import warning since upgrading Convex

After upgrading from Convex 1.0.3 to 1.3.1, I'm getting an import error:
- warn ../../node_modules/node-fetch/lib/index.js
Module not found: Can't resolve 'encoding' in '/Users/matt/Dev/whatsnext/chart-studio/node_modules/node-fetch/lib'

Import trace for requested module:
../../node_modules/node-fetch/lib/index.js
../../node_modules/convex/dist/esm/browser/http_client-node.js
../../node_modules/convex/dist/esm/browser/index-node.js
./src/utils/convex.ts
./src/app/project/[id]/page.tsx


I'm using a helper to setup Convex+Clerk and calling it from a NextJS app router page on the server (was previously working fine):
import { auth } from "@clerk/nextjs";
import { ConvexHttpClient } from "convex/browser";

/**
 * Return a ConvexHttpClient that can be used in server-side contexts.
 */
export async function getConvex(): Promise<ConvexHttpClient> {
  const { userId, getToken } = auth();
  if (!userId) {
    // Clerk middleware should handle this for us.
    throw new Error("Unexpected: user not signed in");
  }

  const token = await getToken({
    template: "convex",
  });

  if (!token) {
    throw new Error("Unexpected: failed to get Clerk token");
  }

  const url = process.env.NEXT_PUBLIC_CONVEX_URL;
  if (!url) {
    throw new Error("Unexpected: NEXT_PUBLIC_CONVEX_URL not found: ");
  }

  const client = new ConvexHttpClient(url);
  client.setAuth(token);

  return client;
}


Anything I need to change after upgrading?
Was this page helpful?