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

Remove web-streams-polyfill and abort controller polyfill #614

Closed
wants to merge 6 commits into from

Conversation

jacoblee93
Copy link

@jacoblee93 jacoblee93 commented Jan 8, 2024

Fixes #613

@jacoblee93 jacoblee93 requested a review from a team as a code owner January 8, 2024 23:27
@jacoblee93
Copy link
Author

jacoblee93 commented Jan 9, 2024

I added "lib": ["DOM"], to the tsconfig.json file to fix typing, and also removed the AbortController polyfill (this has been supported in Node since version 15: https://developer.mozilla.org/en-US/docs/Web/API/AbortController#browser_compatibility)

I was able to set up tests via the OpenAPI spec, seems like there's a few unrelated errors:

Screenshot 2024-01-09 at 8 48 30 AM

This is a bit bigger of a change than initially planned, but should be supported by all LTS Node versions. You can also add special instructions for people to polyfill Node 16 like this if you're very worried:

https://js.langchain.com/docs/get_started/installation#unsupported-nodejs-16

LMK what you think!

@jacoblee93
Copy link
Author

May also be worth removing node-fetch since native fetch is now in Node 18 to avoid weird bundler issues, but that would be another PR.

@jacoblee93 jacoblee93 changed the title Remove web-streams-polyfill Remove web-streams-polyfill and abort controller polyfill Jan 9, 2024
@rattrayalex
Copy link
Collaborator

rattrayalex commented Jan 10, 2024

May also be worth removing node-fetch since native fetch is now in Node 18 to avoid weird bundler issues, but that would be another PR.

It is indeed: #402

Copy link
Collaborator

@rattrayalex rattrayalex left a comment

Choose a reason for hiding this comment

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

Thank you Jacob!

Will need to have a member of our team review more thoroughly, but first will need to resolve question around DOM

@@ -3,7 +3,7 @@
"exclude": ["src/_shims/**/*-deno.ts"],
"compilerOptions": {
"target": "es2020",
"lib": ["es2020"],
Copy link
Collaborator

Choose a reason for hiding this comment

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

ah, sadly I don't think this is an acceptable change b/c we don't want to drag DOM types into our users' projects if they are in a Node setting. Do you remember why it was needed?

Copy link
Author

Choose a reason for hiding this comment

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

ReadableStream isn't defined in the base typing - let me see if I can find another workaround.

@rattrayalex
Copy link
Collaborator

BTW why is this only a partial fix?

@jacoblee93
Copy link
Author

BTW why is this only a partial fix?

Ah sorry that's a typo, another PR I did for LangChain.js was a partial fix for some typing issues we were seeing and I think my mind was on that.

@jacoblee93
Copy link
Author

jacoblee93 commented Jan 10, 2024

With some light Googling, it seems that the only way to get the ReadableStream type without getting hacky and potentially causing more issues seems to be to include DOM in tsconfig.json.

We've been doing it upstream in LangChain.js for a while now with (seemingly) good compatibility:

https://github.com/langchain-ai/langchainjs/blob/main/langchain/tsconfig.json#L10

But if we don't feel comfortable doing that here, then perhaps it's best to hope for a good downstream resolution here and bump the polyfill later on:

MattiasBuelens/web-streams-polyfill#141

@rattrayalex
Copy link
Collaborator

rattrayalex commented Jan 10, 2024

K, then yes that might be best… 

Is ReadableStream in the node types?

If so, maybe we want to reexport from our node and web shims, rather than remove it?

@jacoblee93
Copy link
Author

This has been fixed in the downstream polyfill - feel free to close this!

MattiasBuelens/web-streams-polyfill#142

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.

Remove unnecessary web-streams-polyfill polluting global namespace
2 participants