hatchet-dev / hatchet-typescript

Hatchet Typescript SDK for Interacting with the Hatchet Engine
10 stars 5 forks source link

TypeError when importing into a JS project #227

Open theabhinavdas opened 1 month ago

theabhinavdas commented 1 month ago

Firstly, thank you for this amazing project!

I'm trying to use hatchet-typescript in a JS project by installing it via npm i @hatchet-dev/typescript-sdk, then importing Hatchet with import Hatchet from "@hatchet-dev/typescript-sdk"; and finally initializing like const hatchet = Hatchet.init(config); . This gives me the following error:

TypeError: Hatchet.init is not a function

Is this not the right way to use this SDK in a JS project?

theabhinavdas commented 1 month ago

On further exploration, we may console.log(Hatchet); to see the Hatchet object looks like:

{
  ConcurrencyLimitStrategy: [Getter],
  WorkflowConcurrency: [Getter],
  HatchetTimeoutSchema: [Getter],
  CreateWorkflowSchema: [Getter],
  CreateRateLimitSchema: [Getter],
  CreateStepSchema: [Getter],
  Context: [Getter],
  Worker: [Getter],
  APIContracts: [Getter],
  Api: [Getter],
  AdminClient: [Getter],
  default: [class HatchetClient]
}

It actually doesn't have an init() function but we see that HatchetClient (at ./node_modules/@hatchet-dev/typescript-sdk/clients/hatchet-client/hatchet-client.d.ts) does have a static init(...) function and that's coming from default.

So it seems like using Hatchet.default.init(...) fixes this issue. Will wait for authors to verify and close.

rossirpaulo commented 1 week ago

Yep! I'm dealing with the same problem, even when writing TS file and building with esbuild...

sberryman-mh commented 1 day ago

This was my solution using it inside a remix project (vite)

import HatchetModule from '@hatchet-dev/typescript-sdk'

// Use type assertion to access the default export
const Hatchet = (HatchetModule as any).default || HatchetModule