Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade app to use Pinecone 3.0.x #17

Merged
merged 3 commits into from
Aug 27, 2024
Merged

Upgrade app to use Pinecone 3.0.x #17

merged 3 commits into from
Aug 27, 2024

Conversation

aulorbe
Copy link
Collaborator

@aulorbe aulorbe commented Aug 26, 2024

Problem

We on the SDKs team have since published a new version of our Typescript client. This PR simply updates some dependencies in order to work with the new client + changes a couple import stmts that are required in order to work with newer code.

*****Note: this PR will only work once the client's upcoming patch release is pushed to npm (3.0.2). So, do not merge this until then.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Infrastructure change (CI configs, etc)
  • Non-code change (docs, etc)
  • None of the above: (explain here)

Test Plan

Everything works when launching this app into production via Vercel, with the newest Pinecone Typescript client code (not yet pushed to npm).


@aulorbe
Copy link
Collaborator Author

aulorbe commented Aug 26, 2024

(CI failures should resolve once 3.0.2 is pushed to npm)

Copy link
Collaborator

@rschwabco rschwabco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@@ -1,4 +1,4 @@
import cheerio from 'cheerio';
import * as cheerio from 'cheerio';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious - why this is required?

Copy link
Collaborator Author

@aulorbe aulorbe Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what my IDE told me, since cheerio uses CJS not ESM, it does not have a default export for its functionality. It seems that the previous syntax might've worked for some users/IDEs, but for those using strict module resolution rules (e.g. needing to differentiate btwn CJS and ESM syntax), the old way of importing cheerio wouldn't have worked (it didn't for me). This new syntax is apparently the 'correct and intended' way to import CJS modules.

When I ask ChatGPT why exactly, it gave me this:

  1. import * as cheerio from 'cheerio';
    This is the recommended syntax when importing a CommonJS module in TypeScript. It imports the entire module as an object, which is the correct approach for modules that don’t explicitly define a default export.

Here's why this is recommended:

CommonJS Modules: In a CommonJS module like cheerio, the export is an object (module.exports). When you use import * as cheerio from 'cheerio';, you are effectively importing that entire object, which is the correct and intended behavior.

Type Safety: This approach ensures that TypeScript understands the module is being imported as a namespace object, making the type system more accurate.

Why It Matters
Using import cheerio from 'cheerio'; with a CommonJS module might work because of TypeScript's compatibility features, but it's not technically correct, and it can cause confusion or issues in certain setups, especially when you’re bundling your code or using more strict module resolution settings.

Using import * as cheerio from 'cheerio'; ensures that your code is correctly handling the module import, particularly in environments that distinguish between CommonJS and ESModules.

I've been using pretty strict module resolution rules in another project that I'm bundling this app with, so it's likely a holdover from that.

Copy link
Collaborator

@rschwabco rschwabco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm - pending tests passing

@aulorbe aulorbe merged commit 0361bcb into main Aug 27, 2024
3 checks passed
@aulorbe aulorbe deleted the Audrey/migrate-to-v3x branch August 27, 2024 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants