I just created a brand new Next.js project that should integrate with "replicate": "^0.11.0", but I keep getting this error when calling the run function.
TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
This is my function, as simple as it gets:
import Replicate from "replicate";
export async function getOutput(input) {
const replicate = new Replicate({ auth: process.env.REPLICATE_AUTH_KEY });
// Tried these, neither worked
// replicate.fetch = fetch;
// replicate.fetch = global.fetch;
// replicate.fetch = globalThis.fetch;
return await replicate.run(process.env.REPLICATE_IDENTIFIER, { input });
}
Does it mean Replicate is supposed to be used server-side only (e.g.: Node.js) and can't be called from the browser?
Edit: I managed to make it work only on Node.js, but only if I set the node-fetch (note: must be version 2 if using CommonJS instead of ES modules) as the fetch option, otherwise I get a ReferenceError: fetch is not defined.
import fetch from 'node-fetch';
import Replicate from "replicate";
export async function getOutput(input) {
const replicate = new Replicate({
auth: process.env.REPLICATE_AUTH_KEY,
fetch: fetch,
});
return await replicate.run(process.env.REPLICATE_IDENTIFIER, { input });
}
Is there anything in the documentation that I might have missed that explains the right way to go about it?
Also, would appreciate it if you could have the options.fetch documented, as I only found out about it after reading the source code.
I just created a brand new Next.js project that should integrate with
"replicate": "^0.11.0", but I keep getting this error when calling therunfunction.This is my function, as simple as it gets:
Does it mean Replicate is supposed to be used server-side only (e.g.: Node.js) and can't be called from the browser?
Edit: I managed to make it work only on Node.js, but only if I set the
node-fetch(note: must be version 2 if using CommonJS instead of ES modules) as the fetch option, otherwise I get aReferenceError: fetch is not defined.Is there anything in the documentation that I might have missed that explains the right way to go about it?
Also, would appreciate it if you could have the
options.fetchdocumented, as I only found out about it after reading the source code.