import { Pinecone } from "@pinecone-database/pinecone";
async function initPinecone() {
try {
const pinecone = new Pinecone({
apiKey: process.env.PINECONE_API_KEY,
});
return pinecone;
} catch (error) {
console.log("error", error);
}
}
export const pinecone = await initPinecone();
Migrating to new Pinecone version “@pinecone-database/pinecone”: “^2.2.2”, in Next JS and keep getting error
TypeError: _pinecone_database_pinecone__WEBPACK_IMPORTED_MODULE_0__.Pinecone is not a constructor
Any help is appreciated, thanks.
Hi @kevinsuntopdev, and welcome to the Pinecone community forums!
Thank you for your question.
Given that you’re using Next.js, does the error persist if you kill the hosting process npm run dev
and delete your .next
folder in the same directory then restart local dev mode with npm run dev
?
I sometimes see that exact Webpack error in a transient manner for a variety of different libraries.
I also have a sample TypeScript repo here where I’ve set up Pinecone that you could reference.
I’ll update it now to use the latest Pinecone client version that you’re running and see if I have any issues…
Hi @kevinsuntopdev,
I just updated my sample repo which I linked above to use the exact same version of the Pinecone client that you’re running, and my Pinecone client was successfully instantiated and my repo created the target index correctly.
Therefore, my current best recommendations are:
- Clean up your
.next
folder and restart your app to see if it was indeed a transient Webpack error
- See if using the patterns here2. changes anything for you.
Hope that helps!
Best,
Zack