Skip to content

RangeError: Maximum call stack size exceeded when uploading image (in version 0.30.1) #270

Closed
@ocluf

Description

@ocluf

I get the following error:

RangeError: Maximum call stack size exceeded
    at bytesToBase64 (/Users/fwtaen/projects/viralgifs/node_modules/.pnpm/replicate@0.30.1/node_modules/replicate/lib/util.js:148:35)
    at /Users/fwtaen/projects/viralgifs/node_modules/.pnpm/replicate@0.30.1/node_modules/replicate/lib/util.js:303:18
    at transform (/Users/fwtaen/projects/viralgifs/node_modules/.pnpm/replicate@0.30.1/node_modules/replicate/lib/util.js:329:16)
    at transform (/Users/fwtaen/projects/viralgifs/node_modules/.pnpm/replicate@0.30.1/node_modules/replicate/lib/util.js:324:25)
    at transformFileInputsToBase64EncodedDataURIs (/Users/fwtaen/projects/viralgifs/node_modules/.pnpm/replicate@0.30.1/node_modules/replicate/lib/util.js:277:16)
    at transformFileInputs (/Users/fwtaen/projects/viralgifs/node_modules/.pnpm/replicate@0.30.1/node_modules/replicate/lib/util.js:238:22)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Replicate.createPrediction (/Users/fwtaen/projects/viralgifs/node_modules/.pnpm/replicate@0.30.1/node_modules/replicate/lib/predictions.js:33:16)
    at async Replicate.run (/Users/fwtaen/projects/viralgifs/node_modules/.pnpm/replicate@0.30.1/node_modules/replicate/index.js:140:20)
    at async main (file:///Users/fwtaen/projects/viralgifs/index.js:17:18)
done

When trying to upload an image like this

import { readFile } from 'fs/promises';

import Replicate from 'replicate';

const replicate = new Replicate({
	auth: process.env.REPLICATE_AUTH
});

async function main() {
	try {
		let file = await readFile(
			'/Users/fwtaen/projects/viralgifs/static/matrix_images/frame_0185.png'
		);

		const output = await replicate.run(
			'adirik/grounding-dino:efd10a8ddc57ea28773327e881ce95e20cc1d734c589f7dd01d2036921ed78aa',
			{
				input: {
					image: file,
					query: 'red pill',
					box_threshold: 0.2,
					text_threshold: 0.2,
					show_visualisation: true
				}
			}
		);
		console.log(output);
	} catch (error) {
		console.error(error);
	} finally {
		console.log('done');
	}
}
main();

I already found this issue #247 which says a fix has been merged in v 0.30.0. However both 0.30.0 and 0.30.1 still give me this error while using pnpm install replicate/replicate-javascript#fix-rangeerror seemed to fix it for me.

I'm on node v20.11.0` M1 pro, macos 14.4.1 (23E224)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions