Open YaronRosh opened 8 months ago
Can you share your tsconfig? This is likely an issue in your config.
{
"compilerOptions": {
"outDir": "dist",
"incremental": true,
"sourceMap": true,
"lib": ["esnext", "dom"],
"jsx": "react",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"baseUrl": ".",
"module": "commonjs",
"rootDir": ".",
"target": "es6",
"noImplicitAny": false,
"moduleResolution": "Node",
"allowJs": true,
"resolveJsonModule": true
},
"include": [
"src",
"__tests__"
],
"exclude": [
"node_modules",
"./_isolated_",
"./workspaces",
"**/dist"
]
}
Can you try "moduleResolution": "nodeNext"
instead of "Node"
?
If that presents other challenges for you, you can try adding this line before your first import of the package:
import '@anthropic-ai/sdk/shims/node'
More information here: https://github.com/anthropics/anthropic-sdk-typescript/tree/main/src/_shims#readme
it now fails on something else
with or without the shim
import '@anthropic-ai/sdk/shims/node'
../node_modules/@anthropic-ai/bedrock-sdk/client.d.ts:41:15 - error TS2416: Property 'prepareRequest' in type 'AnthropicBedrock' is not assignable to the same property in base type 'APIClient'.
Type '(request: RequestInit, { url, options }: { url: string; options: import("/Users/yaronrosh/logzio/gaia-hermes-ws/node_modules/@anthropic-ai/sdk/core").FinalRequestOptions<unknown>; }) => Promise<...>' is not assignable to type '(request: import("/Users/yaronrosh/logzio/gaia-hermes-ws/node_modules/@types/node-fetch/index").RequestInit, { url, options }: { url: string; options: import("/Users/yaronrosh/logzio/gaia-hermes-ws/node_modules/@anthropic-ai/sdk/core").FinalRequestOptions<unknown>; }) => Promise<...>'.
Types of parameters 'request' and 'request' are incompatible.
Type 'import("/node_modules/@types/node-fetch/index").RequestInit' is not assignable to type 'RequestInit'.
Types of property 'body' are incompatible.
Type 'import("/node_modules/@types/node-fetch/index").BodyInit' is not assignable to type 'BodyInit'.
Type 'ReadableStream' is not assignable to type 'BodyInit'.
Type 'ReadableStream' is missing the following properties from type 'ReadableStream<any>': locked, cancel, getReader, pipeThrough, and 3 more.
41 protected prepareRequest(request: RequestInit, { url, options }: {
~~~~~~~~~~~~~~
../node_modules/@anthropic-ai/bedrock-sdk/client.d.ts:45:5 - error TS2416: Property 'buildRequest' in type 'AnthropicBedrock' is not assignable to the same property in base type 'APIClient'.
Type '(options: FinalRequestOptions<unknown>) => { req: RequestInit; url: string; timeout: number; }' is not assignable to type '<Req>(options: FinalRequestOptions<Req>) => { req: RequestInit; url: string; timeout: number; }'.
Call signature return types '{ req: RequestInit; url: string; timeout: number; }' and '{ req: RequestInit; url: string; timeout: number; }' are incompatible.
The types of 'req.body' are incompatible between these types.
Type 'BodyInit' is not assignable to type 'import("/Users/yaronrosh/logzio/gaia-hermes-ws/node_modules/@types/node-fetch/index").BodyInit'.
Type 'Blob' is not assignable to type 'BodyInit'.
Type 'Blob' is missing the following properties from type 'URLSearchParams': append, delete, entries, forEach, and 8 more.
45 buildRequest(options: Core.FinalRequestOptions<unknown>): {
~~~~~~~~~~~~
Got it. Does "moduleResolution": "nodeNext"
help?
Answering on behalf of Yaron, it didn't help as well.
hmm… that's surprising. Can you share a codesandbox with minimal repro?
I also get exactly the same error when I set "module": "NodeNext", "moduleResolution": "NodeNext",
. I also started from the same error, pretty much copying the example:
import AnthropicBedrock from '@anthropic-ai/bedrock-sdk';
const createInput = async (messages) => {
const client = new AnthropicBedrock({
awsAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
awsSecretKey: process.env.AWS_ACCESS_KEY_ID,
awsRegion: process.env.AWS_DEFAULT_REGION,
});
const message = await client.messages.create({
model: 'anthropic.claude-3-5-sonnet-20240620-v1:0',
max_tokens: 256,
messages
});
return message;
}
Can you share a codesandbox with a minimal repro? Without more details, we can't really directly fix this.
You might also try import '@anthropic-ai/sdk/shims/node'
or import '@anthropic-ai/sdk/shims/web'
before your first import of the SDK.
This repro is pretty much the same as the docs; please run npm run build
in this, https://codesandbox.io/p/sandbox/angry-thunder-ll36v2. Note it is the tsc
command that fails.
I worked around this by converting the ts file to a js file with JSDOC comments, but that is a work around, not a "solution"
Thanks, we'll take a look!
@S-unya unfortunately I'm getting a "Sandbox not found" error message from https://codesandbox.io/p/sandbox/angry-thunder-ll36v2, is it private?
having compilation issue with the
@anthropic-ai/bedrock-sdk
, using in node js + tsusing
@anthropic-ai/bedrock-sdk
: 0.9.2typescript
: 5.2.2