listIndexes().some error

async function initializeStores() {
  // Initialize Pinecone client
  const pinecone = new Pinecone({
    apiKey: process.env.PINECONE_API_KEY!,
    environment: process.env.PINECONE_ENVIRONMENT! // Add this if using older SDK version
  });

  // Create index if it doesn't exist
  const { indexes } = await pinecone.listIndexes();
  if (!indexes.some((index: { name: string }) => index.name === indexName)) {
    await pinecone.createIndex({
      name: indexName,
      dimension: 768,
      metric: "cosine",
      spec: {
        serverless: {
          cloud: "aws",
          region: "us-west-2",
        },
      },
    });

    // Wait for index initialization
    await new Promise(resolve => setTimeout(resolve, 60000));
  }
  // ... rest of the code
}

in my code above i want to create a index if it already doesnt exisits, but i get this error

**`\node_modules\ts-node\src\index.ts:859
return new TSError(diagnosticText, diagnosticCodes, diagnostics);
^
TSError: ⨯ Unable to compile TypeScript:
pinecone_server.ts:33:5 - error TS2353: Object literal may only specify known properties, and ‘environment’ does not exist in type ‘PineconeConfiguration’.

33 environment: process.env.PINECONE_ENVIRONMENT!, // Add this if using older SDK version
~~~~~~~~~~~
pinecone_server.ts:39:16 - error TS2339: Property ‘some’ does not exist on type ‘IndexList’.

39 if (!indexes.some((index: { name: string }) => index.name === indexName)) {
~~~~

at createTSError node_modules\ts-node\src\index.ts:1617:30)       
at loadTS (node:internal/modules/cjs/loader:1831:10)
at Object.require.extensions.<computed> [as .ts] (backend\node_modules\ts-node\src\index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:1473:32)
at Function._load (node:internal/modules/cjs/loader:1285:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14) {

diagnosticCodes: [ 2353, 2339 ]`**

so how do i simply achieve that?

Hi @parjanyag,

Welcome to the Pinecone community!

Can you try removing the environment: process.env.PINECONE_ENVIRONMENT!? As the error message says, that setting is for out-dated versions of the SDK.

Best,
Jesse

1 Like