Difficulty Setting up with NextJS

super excited about the launch on vercel! however I keep getting the following errors when I try to launch on localhost:
OPTIONS /api/rivet/actors?namespace=housingcloud-077e-qa-9d07 404 in 22ms
level=WARN msg="engine process exited" code= signal=SIGKILL
Error: engine health check failed after 100 retries: TypeError: fetch failed
at waitForEngineHealth (webpack-internal:///(rsc)/../../node_modules/rivetkit/dist/tsup/chunk-S5K7CB2F.js:3004:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async ensureEngineProcess (webpack-internal:///(rsc)/../../node_modules/rivetkit/dist/tsup/chunk-S5K7CB2F.js:2867:3)
at async Promise.all (index 0)
⨯ unhandledRejection: Error: engine health check failed after 100 retries: TypeError: fetch failed
at waitForEngineHealth (webpack-internal:///(rsc)/../../node_modules/rivetkit/dist/tsup/chunk-S5K7CB2F.js:3004:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async ensureEngineProcess (webpack-internal:///(rsc)/../../node_modules/rivetkit/dist/tsup/chunk-S5K7CB2F.js:2867:3)
at async Promise.all (index 0)
⨯ unhandledRejection: Error: engine health check failed after 100 retries: TypeError: fetch failed
at waitForEngineHealth (webpack-internal:///(rsc)/../../node_modules/rivetkit/dist/tsup/chunk-S5K7CB2F.js:3004:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async ensureEngineProcess (webpack-internal:///(rsc)/../../node_modules/rivetkit/dist/tsup/chunk-S5K7CB2F.js:2867:3)
at async Promise.all (index 0)

OPTIONS /api/rivet/actors?namespace=housingcloud-077e-qa-9d07 404 in 22ms
level=WARN msg="engine process exited" code= signal=SIGKILL
Error: engine health check failed after 100 retries: TypeError: fetch failed
at waitForEngineHealth (webpack-internal:///(rsc)/../../node_modules/rivetkit/dist/tsup/chunk-S5K7CB2F.js:3004:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async ensureEngineProcess (webpack-internal:///(rsc)/../../node_modules/rivetkit/dist/tsup/chunk-S5K7CB2F.js:2867:3)
at async Promise.all (index 0)
⨯ unhandledRejection: Error: engine health check failed after 100 retries: TypeError: fetch failed
at waitForEngineHealth (webpack-internal:///(rsc)/../../node_modules/rivetkit/dist/tsup/chunk-S5K7CB2F.js:3004:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async ensureEngineProcess (webpack-internal:///(rsc)/../../node_modules/rivetkit/dist/tsup/chunk-S5K7CB2F.js:2867:3)
at async Promise.all (index 0)
⨯ unhandledRejection: Error: engine health check failed after 100 retries: TypeError: fetch failed
at waitForEngineHealth (webpack-internal:///(rsc)/../../node_modules/rivetkit/dist/tsup/chunk-S5K7CB2F.js:3004:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async ensureEngineProcess (webpack-internal:///(rsc)/../../node_modules/rivetkit/dist/tsup/chunk-S5K7CB2F.js:2867:3)
at async Promise.all (index 0)

I'm following the NextJS setup guide. https://www.rivet.dev/docs/actors/quickstart/next-js/ this is my setup:
import { actor, setup } from 'rivetkit';

import { aiAgent } from './actors/ai';

export const counter = actor({
state: { count: 0 },
actions: {
increment: (c, x: number) => {
c.state.count += x;
c.broadcast('newCount', c.state.count);
return c.state.count;
},
},
});

export const registry = setup({
use: { counter },
});
import { actor, setup } from 'rivetkit';

import { aiAgent } from './actors/ai';

export const counter = actor({
state: { count: 0 },
actions: {
increment: (c, x: number) => {
c.state.count += x;
c.broadcast('newCount', c.state.count);
return c.state.count;
},
},
});

export const registry = setup({
use: { counter },
});
when I access http://localhost:3000/api/rivet/actors?namespace=default I get Not Found (RivetKit) but when I access /metadata I get
{
"runtime": "rivetkit",
"version": "2.0.18",
"runner": {
"kind": {
"serverless": {}
}
},
"actorNames": {
"counter": {
"metadata": {}
}
},
"clientEndpoint": "http://localhost:6420"
}
{
"runtime": "rivetkit",
"version": "2.0.18",
"runner": {
"kind": {
"serverless": {}
}
},
"actorNames": {
"counter": {
"metadata": {}
}
},
"clientEndpoint": "http://localhost:6420"
}
I'm using turborepo if that matters.
Rivet
Next.js Quickstart - Rivet
Get started with Rivet Actors in Next.js
17 Replies
Nathan
Nathan2mo ago
afk rn, will take a look in a couple hours @sylvester stallone thanks for reaching out and reporting the issue what OS are you running on? can you try running with debug logs by using the LOG_LEVEL env var, like this:
LOG_LEVEL=debug next dev
LOG_LEVEL=debug next dev
then send the output?
Nathan
Nathan2mo ago
it'd be really helpful if you can try cloning our template to see if that works on your machine too to rule out configuration issues – https://github.com/rivet-dev/template-vercel
GitHub
GitHub - rivet-dev/template-vercel: Next.js template with RivetKit ...
Next.js template with RivetKit integration for Vercel deployment - rivet-dev/template-vercel
sylvester stallone
sylvester stalloneOP2mo ago
macos
Nathan
Nathan2mo ago
i’ll hop on in a few to see if i can help figure this out, lmk when you can send the debug logs
sylvester stallone
sylvester stalloneOP2mo ago
this is if I connect to a custom nodejs server
level=DEBUG msg="making api call" method=GET url="http://localhost:6420/metadata?namespace=default"
level=DEBUG msg="sending http request" url="http://localhost:6420/metadata?namespace=default" encoding=json
level=INFO msg="received new client endpoint from metadata" endpoint=http://127.0.0.1:6420
level=INFO msg="connected to rivetkit manager" runtime=rivetkit version=2.0.18 runner="{\"kind\":{\"normal\":{}}}"
level=DEBUG msg="making api call" method=GET url="http://localhost:6420/metadata?namespace=default"
level=DEBUG msg="sending http request" url="http://localhost:6420/metadata?namespace=default" encoding=json
level=INFO msg="received new client endpoint from metadata" endpoint=http://127.0.0.1:6420
level=INFO msg="connected to rivetkit manager" runtime=rivetkit version=2.0.18 runner="{\"kind\":{\"normal\":{}}}"
note that even though it connects the counter doesn't work
sylvester stallone
sylvester stalloneOP2mo ago
here are the logs when I try to run it on nextjs setup (with api/all/rivet) etc
sylvester stallone
sylvester stalloneOP2mo ago
this is the setup
'use client';

import { useState } from 'react';
import { createRivetKit } from '@rivetkit/react';

import type { registry } from '@hou/ai/src/rivet/registry';

const { useActor } = createRivetKit<typeof registry>(
'http://localhost:3000/api/rivet',
);

export function Counter() {
const [count, setCount] = useState(0);

const counter = useActor({
name: 'counter',
key: ['test'],
});

counter.useEvent('newCount', (x: number) => setCount(x));

const increment = async () => {
await counter.connection?.increment(1);
};

return (
<div>
<p>Count: {count}</p>
<button onClick={increment}>Increment</button>
</div>
);
}
'use client';

import { useState } from 'react';
import { createRivetKit } from '@rivetkit/react';

import type { registry } from '@hou/ai/src/rivet/registry';

const { useActor } = createRivetKit<typeof registry>(
'http://localhost:3000/api/rivet',
);

export function Counter() {
const [count, setCount] = useState(0);

const counter = useActor({
name: 'counter',
key: ['test'],
});

counter.useEvent('newCount', (x: number) => setCount(x));

const increment = async () => {
await counter.connection?.increment(1);
};

return (
<div>
<p>Count: {count}</p>
<button onClick={increment}>Increment</button>
</div>
);
}
cc @Nathan
Nathan
Nathan2mo ago
looking in to this, thx! spent a bit trying to reproduce this. - i just cut a release for RivetKit 2.0.19, can you try running this version? - if the error persists, can you try running "/Users/sasha/Library/Application Support/rivetkit/web-644b5f37/bin/rivet-engine-25.8.1" start in your terminal and see what it says?
sylvester stallone
sylvester stalloneOP2mo ago
after upgrade: OPTIONS /api/rivet/actors?namespace=default 404 in 33ms level=WARN msg="engine process exited, please report this error" code= signal=SIGKILL issues=https://github.com/rivet-dev/rivetkit/issues support=https://rivet.dev/discord PUT /api/inngest 200 in 123ms Error: engine health check failed after 100 retries: TypeError: fetch failed at waitForEngineHealth (webpack-internal:///(rsc)/../../node_modules/rivetkit/dist/tsup/chunk-L3YPHXPE.js:3040:15) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async ensureEngineProcess (webpack-internal:///(rsc)/../../node_modules/rivetkit/dist/tsup/chunk-L3YPHXPE.js:2870:3) at async Promise.all (index 0) ⨯ unhandledRejection: Error: engine health check failed after 100 retries: TypeError: fetch failed at waitForEngineHealth (webpack-internal:///(rsc)/../../node_modules/rivetkit/dist/tsup/chunk-L3YPHXPE.js:3040:15) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async ensureEngineProcess (webpack-internal:///(rsc)/../../node_modules/rivetkit/dist/tsup/chunk-L3YPHXPE.js:2870:3) at async Promise.all (index 0) ⨯ unhandledRejection: Error: engine health check failed after 100 retries: TypeError: fetch failed at waitForEngineHealth (webpack-internal:///(rsc)/../../node_modules/rivetkit/dist/tsup/chunk-L3YPHXPE.js:3040:15) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async ensureEngineProcess (webpack-internal:///(rsc)/../../node_modules/rivetkit/dist/tsup/chunk-L3YPHXPE.js:2870:3) at async Promise.all (index 0)
GitHub
rivet-dev/rivetkit
A library for building stateful workloads anywhere - rivet-dev/rivetkit
Discord
Join the Rivet Developer Network Discord Server!
Build and scale stateful workloads. Rivet is a library for long-lived processes with durable state, realtime, and scalability. Easily self-hostable and works with your infrastructure. | 1386 members
sylvester stallone
sylvester stalloneOP2mo ago
sasha@Mac ~ % "/Users/sasha/Library/Application Support/rivetkit/web-644b5f37/bin/rivet-engine-25.8.1" start
zsh: killed start
sasha@Mac ~ % "/Users/sasha/Library/Application Support/rivetkit/web-644b5f37/bin/rivet-engine-25.8.1" start
zsh: killed start
Nathan
Nathan2mo ago
can you try removing that file (rm "/Users/sasha/Library/Application Support/rivetkit/web-644b5f37/bin/rivet-engine-25.8.1") then starting the dev server again?
sylvester stallone
sylvester stalloneOP2mo ago
OPTIONS /api/rivet/actors?namespace=default 404 in 23ms OPTIONS /api/rivet/actors?namespace=default 404 in 28ms OPTIONS /api/rivet/actors?namespace=default 404 in 74ms OPTIONS /api/rivet/actors?namespace=default 404 in 13ms PUT /api/inngest 200 in 330ms OPTIONS /api/rivet/actors?namespace=default 404 in 12ms level=WARN msg="engine binary download is taking longer than expected, please be patient" version=25.8.1 OPTIONS /api/rivet/actors?namespace=default 404 in 22ms GET /api/rivet/metadata 200 in 10ms PUT /api/inngest 200 in 38ms OPTIONS /api/rivet/actors?namespace=default 404 in 24ms PUT /api/inngest 200 in 36ms OPTIONS /api/rivet/actors?namespace=default 404 in 32ms PUT /api/inngest 200 in 47ms PUT /api/inngest 200 in 44ms PUT /api/inngest 200 in 42ms PUT /api/inngest 200 in 53ms OPTIONS /api/rivet/actors?namespace=default 404 in 52ms
Nathan
Nathan2mo ago
looks like it's going in the right direction. can you run this again with LOG_LEVEL=debug? the 404 on /api/rivet/actors looks like there might be a configuration issue on your client. can you send how your calling createRivetKit? you should see a request to GET /metadata before anything else
sylvester stallone
sylvester stalloneOP2mo ago
'use client'; import { useState } from 'react'; import { createRivetKit } from '@rivetkit/react'; import type { registry } from '@hou/ai/src/rivet/registry'; const { useActor } = createRivetKit<typeof registry>( 'http://localhost:3000/api/rivet', ); export function Counter() { const [count, setCount] = useState(0); const counter = useActor({ name: 'counter', key: ['test'], }); counter.useEvent('newCount', (x: number) => setCount(x)); const increment = async () => { await counter.connection?.increment(1); }; return ( <div> <p>Count: {count}</p> <button onClick={increment}>Increment</button> </div> ); } thgis is where I'm calling
sylvester stallone
sylvester stalloneOP2mo ago
Rivet
Next.js Quickstart - Rivet
Get started with Rivet Actors in Next.js
Nathan
Nathan2mo ago
it looks like i fixed the original issue but you should be seeing a request to GET /api/rivet/metadata that's not getting sent. can you check your browser's request log for this? updating your import to:
import { createRivetKit } from '@rivetkit/next-js/client';
import { createRivetKit } from '@rivetkit/next-js/client';
and verify that both @Rivetkit/next-js and rivetkit are on v2.0.20?

Did you find this page helpful?