RangeError: Maximum call stack size exceeded when uploading image (in version 0.30.1)
ocluf opened this issue · 4 comments
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)
I think I messed up the version in this issue. When install 0.30.2 with pnpm i replicate@latest I still get this:
RangeError: Maximum call stack size exceeded
at bytesToBase64 (/Users/fwtaen/projects/viralgifs/node_modules/.pnpm/replicate@0.30.2/node_modules/replicate/lib/util.js:148:35)
at /Users/fwtaen/projects/viralgifs/node_modules/.pnpm/replicate@0.30.2/node_modules/replicate/lib/util.js:303:18
at transform (/Users/fwtaen/projects/viralgifs/node_modules/.pnpm/replicate@0.30.2/node_modules/replicate/lib/util.js:329:16)
at transform (/Users/fwtaen/projects/viralgifs/node_modules/.pnpm/replicate@0.30.2/node_modules/replicate/lib/util.js:324:25)
at transformFileInputsToBase64EncodedDataURIs (/Users/fwtaen/projects/viralgifs/node_modules/.pnpm/replicate@0.30.2/node_modules/replicate/lib/util.js:277:16)
at transformFileInputs (/Users/fwtaen/projects/viralgifs/node_modules/.pnpm/replicate@0.30.2/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.2/node_modules/replicate/lib/predictions.js:33:16)
at async Replicate.run (/Users/fwtaen/projects/viralgifs/node_modules/.pnpm/replicate@0.30.2/node_modules/replicate/index.js:140:20)
at async main (file:///Users/fwtaen/projects/viralgifs/index.js:15:18)
done
I removed the node_modules folder and reinstalled everything with npm to make sure there weren't any issues there. Still got this
node index.js
RangeError: Maximum call stack size exceeded
at bytesToBase64 (/Users/fwtaen/projects/viralgifs/node_modules/replicate/lib/util.js:148:35)
at /Users/fwtaen/projects/viralgifs/node_modules/replicate/lib/util.js:303:18
at transform (/Users/fwtaen/projects/viralgifs/node_modules/replicate/lib/util.js:329:16)
at transform (/Users/fwtaen/projects/viralgifs/node_modules/replicate/lib/util.js:324:25)
at transformFileInputsToBase64EncodedDataURIs (/Users/fwtaen/projects/viralgifs/node_modules/replicate/lib/util.js:277:16)
at transformFileInputs (/Users/fwtaen/projects/viralgifs/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/replicate/lib/predictions.js:33:16)
at async Replicate.run (/Users/fwtaen/projects/viralgifs/node_modules/replicate/index.js:140:20)
at async main (file:///Users/fwtaen/projects/viralgifs/index.js:15:18)
done
Edit: nevermind you just published 0.30.2. That is a quick response even though it doesn't seem to have fixed the problem on my side, thank you!
I just ran into the same problem and in my case it was caused by a missing API token. I forgot to set the environment variable REPLICATE_API_TOKEN. Apparently, if the token is missing, the file uploads fail causing the SDK to fall back to Base64, which runs into the stack limit for larger files. Adding the token fixed it for me, but a better error message from the SDK would be helpful.
Getting this error under the same circumstances in 0.30.2 and 0.31.1. Double checked that my API token is being passed in and force reinstalled packages.