replicate/replicate-javascript

TypeError: replicate_1.default is not a constructor

fedikan opened this issue · 6 comments

I've just downloaded your client, and wanted to do some cool AI generations, but seems like it's not possible right now :(
My replicate module version is replicate@0.21.1
Some code example:

import Replicate from "replicate";


import { GeneratedImageResponse } from 'src/types/generated.image.response';
import { IImageGenerator } from './interfaces';

export const ReplicateID = {
  'stable_diffusion_infinite_zoom': 'arielreplicate/stable_diffusion_infinite_zoom:a2527c5074fc0cf9fa6015a40d75d080d1ddf7082fabe142f1ccd882c18fce61'
}

export class ReplicateService implements IImageGenerator {

  constructor() {
    const replicate = new Replicate({
      auth: process.env.REPLICATE_API_TOKEN,
    });

    this.replicate = replicate;
  }
  private replicate

  async generateImage(config: any, model): Promise<GeneratedImageResponse> {
    const output = await this.replicate.run(
      ReplicateID[model],
      {
        input: {
          prompt: config.prompt
        }
      }
    );
    return output
  }
}
mattt commented

Hi @fedikan. It looks like you're running into an issue with ES modules. If you're using from TypeScript, try adding "esModuleInterop": true to your tsconfig.json file. If that's not the case or doesn't resolve your issue, can you share more information about your project structure?

Hi @fedikan. It looks like you're running into an issue with ES modules. If you're using from TypeScript, try adding "esModuleInterop": true to your tsconfig.json file. If that's not the case or doesn't resolve your issue, can you share more information about your project structure?

It worked, thank you for quick reply <3

mattt commented

So glad to hear it, @fedikan. Happy hacking!

@mattt i'm also experiencing the same issue and i've added "esModuleInterop": true to my tsconfig.json

mattt commented

@davidnjagah Sorry to hear that. Please open a new issue with some details about your project, and I'll do my best to help.