anthropics / anthropic-sdk-typescript

Access to Anthropic's safety-first language model APIs
https://www.npmjs.com/package/@anthropic-ai/sdk
MIT License
725 stars 79 forks source link

`qs` library breaks Edge builds #54

Closed jacoblee93 closed 1 year ago

jacoblee93 commented 1 year ago

This qs library generally has some things that aren't supported in edge environments in a downstream dependency:

test-exports-vercel:build: Failed to compile.
test-exports-vercel:build: 
test-exports-vercel:build: ../node_modules/function-bind/implementation.js
test-exports-vercel:build: Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime 
test-exports-vercel:build: Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation
test-exports-vercel:build: 
test-exports-vercel:build: Import trace for requested module:
test-exports-vercel:build: ../node_modules/function-bind/implementation.js
test-exports-vercel:build: ../node_modules/function-bind/index.js
test-exports-vercel:build: ../node_modules/get-intrinsic/index.js
test-exports-vercel:build: ../node_modules/side-channel/index.js
test-exports-vercel:build: ../node_modules/@anthropic-ai/sdk/node_modules/qs/lib/stringify.js
test-exports-vercel:build: ../node_modules/@anthropic-ai/sdk/node_modules/qs/lib/index.js
test-exports-vercel:build: ../node_modules/@anthropic-ai/sdk/core.mjs
test-exports-vercel:build: ../node_modules/@anthropic-ai/sdk/index.mjs
test-exports-vercel:build: ../langchain/dist/chat_models/anthropic.js
test-exports-vercel:build: ../langchain/chat_models/anthropic.js
test-exports-vercel:build: ./src/entrypoints.js
test-exports-vercel:build: 
test-exports-vercel:build: 
test-exports-vercel:build: > Build failed because of webpack errors

Would love to replace it with an alternative - it's a blocker on https://github.com/hwchase17/langchainjs/pull/1932.

jacoblee93 commented 1 year ago

Here's the bad downstream dep:

https://github.com/Raynos/function-bind/blob/master/implementation.js#L42

rattrayalex commented 1 year ago

Hey @jacoblee93, this has been resolved on the Next.js side in https://github.com/vercel/next.js/pull/52009 – is that sufficient for your needs?

Some additional background in https://github.com/vercel/next.js/discussions/51910 if it's helpful (it documents a workaround for users on older versions of Next)

jacoblee93 commented 1 year ago

Wild! Ok, will see what we can do on our end. Thank you!

rattrayalex commented 1 year ago

Great! If you think version incompatibilities will be a big issue, let me know and we'll see what we can do.

jacoblee93 commented 1 year ago

Bumping next in our build test seems to have fixed it, all good. Thanks for the quick response!