Node.JS Client blocker - [PineconeError: Failed getting project name. TypeError: fetch failed]

I’m having a lot of issues getting the PineconeClient (Node.JS Client) to initialize using Next.js in a route handler (essentially an API route).

I’ve tried quite a few things and nothing seems to be working, from trying out different Node.js versions to setting my API keys using different methods to setting the proejectName before the init.

Here are steps to reproduce:

  1. Create a new next.js application
  2. Set environment variables
  3. Try to initialize the PineconeClient from an API route or route handler.

Result:

- error TypeError: Cannot read properties of undefined (reading 'headers')
    at eval (webpack-internal:///(sc_server)/./node_modules/next/dist/server/future/route-modules/app-route/module.js:254:61)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Ok, this was a mistake on my part, but might be helpful for someone else!

for the Environment, it needs to be an actual environment from Pinecone, i.e. us-west4-gcp-free or something like that.

This may have been apparent to some folks but it certainly wasn’t for me :sweat_smile:.

A few ways to improve this experience:

  1. Throw a better error. Instead of the headers error, say that the environment was not valid
  2. In the documentation, mention that the environment needs to be a valid Pinecone environment region from the Pinecone console. Something like this:
import { PineconeClient } from "@pinecone-database/pinecone";

const pinecone = new PineconeClient();
await pinecone.init({
  environment: "YOUR_ENVIRONMENT", // valid Pinecone environment, like us-west4-gcp-free
  apiKey: "YOUR_API_KEY",
});

Hi dabit3, I ran into the exactly the same issue as you had but it was not due to incorrectly setting Environment or API something like that.

The issue, as I’ve been debugging so far, should be from the lib/memory.ts file.

public async init() {
    if (this.vectorDBClient instanceof PineconeClient) {
      console.log("***")
      await this.vectorDBClient.init({
        apiKey: process.env.PINECONE_API_KEY!,
        environment: process.env.PINECONE_ENVIRONMENT!,
      });
      // this.vectorDBClient.projectName = 'default';
      console.log("****")
    }
  }

Could you please take a look and see if you could find something wrong. Appreciate that!

Github: https://github.com/babelpainterwell/TalkMe