scribble-diffusion icon indicating copy to clipboard operation
scribble-diffusion copied to clipboard

use the replicate npm package

Open zeke opened this issue 2 years ago • 8 comments

https://github.com/replicate/replicate-js

zeke avatar Feb 25 '23 06:02 zeke

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
scribble-diffusion ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 10, 2023 at 5:05AM (UTC)

vercel[bot] avatar Feb 25 '23 06:02 vercel[bot]

This is working locally but the preview app seems to be failing.

index-153743c76e8d4f30.js:1          POST https://scribble-diffusion-git-use-replicate-npm-package-replicate.vercel.app/api/predictions 500

zeke avatar Feb 25 '23 06:02 zeke

$ vercel logs -f "https://scribble-diffusion-git-use-replicate-npm-package-replicate.vercel.app/"

Output:

2023-02-25T06:36:38.252Z  2023-02-25T06:36:38.837Z	c48daf0d-9fff-46cc-ac61-e7fb9411a31e	ERROR	Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'node-fetch' imported from /var/task/node_modules/replicate/lib/ReplicateClient.js
2023-02-25T06:36:38.252Z      at new NodeError (node:internal/errors:393:5)
2023-02-25T06:36:38.252Z      at packageResolve (node:internal/modules/esm/resolve:865:9)
2023-02-25T06:36:38.252Z      at moduleResolve (node:internal/modules/esm/resolve:958:20)
2023-02-25T06:36:38.252Z      at moduleResolveWithNodePath (node:internal/modules/esm/resolve:909:12)
2023-02-25T06:36:38.252Z      at defaultResolve (node:internal/modules/esm/resolve:1173:79)
2023-02-25T06:36:38.252Z      at nextResolve (node:internal/modules/esm/loader:163:28)
2023-02-25T06:36:38.252Z      at ESMLoader.resolve (node:internal/modules/esm/loader:841:30)
2023-02-25T06:36:38.252Z      at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
2023-02-25T06:36:38.252Z      at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
2023-02-25T06:36:38.252Z      at link (node:internal/modules/esm/module_job:75:36) {
2023-02-25T06:36:38.252Z    code: 'ERR_MODULE_NOT_FOUND'
2023-02-25T06:36:38.252Z  }

zeke avatar Feb 25 '23 06:02 zeke

I wonder if https://github.com/vercel/fetch is injecting itself into this somehow and screwing things up...

zeke avatar Feb 25 '23 06:02 zeke

@erbridge any idea what might be wrong here?

zeke avatar Feb 25 '23 06:02 zeke

I wonder if https://github.com/vercel/fetch is injecting itself into this somehow and screwing things up...

It looks like that's supposed to use node-fetch under the hood anyway 🤔.

erbridge avatar Feb 27 '23 16:02 erbridge

Kicking off a redeploy seems to have cleared that error @zeke?

erbridge avatar Feb 27 '23 17:02 erbridge

@erbridge no it's still broken when you try to create a scribble.

zeke avatar Feb 27 '23 19:02 zeke

I would recommend you remove the dependency on node-fetch altogether. All modern JavaScript runtimes, including Node LTS, come with a native fetch method now. The Replicate constructor should still accept a fetch option to use a custom fetch implementation for environments that don't bring their own, or for testing where we want to mock requests.

gr2m avatar Mar 08 '23 04:03 gr2m

It looks like we're using other things from node-fetch besides just fetch like FetchError, Response, etc.

@gr2m can you point to any good reference implementations that are using built-in fetch?

I see this: https://github.com/octokit/request.js/blob/bd72b7be53ab16a6c1c44be99eb73a328fb1e9e4/src/fetch-wrapper.ts#L29-L31

zeke avatar Mar 08 '23 05:03 zeke

It looks like we're using other things from node-fetch besides just fetch like FetchError, Response, etc.

I'm pretty sure we can get the types separately, too.

@gr2m can you point to any good reference implementations that are using built-in fetch?

I removed it from @octokit-next/* packages here: https://github.com/octokit/octokit-next.js/pull/62/files

Basically it works like this

import { Octokit } from "@octokit-next/core"

// use built-in fetch, throws if it is not set
const octokit = new Octokit()

or like this

import { Octokit } from "@octokit-next/core"
import fetch from "node-fetch"

// use your own fetch implementation
const octokit = new Octokit({ request: { fetch }})

gr2m avatar Mar 08 '23 22:03 gr2m

Works on my machine. Now with webhooks. Thanks @erbridge for unblocking all the things.

🪝 received webhook for prediction:  prv72qvwdfcdxalsypyjjlruye

Screenshot 2023-03-09 at 9 07 55 PM

zeke avatar Mar 10 '23 05:03 zeke

This is ready for a review.

zeke avatar Mar 10 '23 05:03 zeke