Service binding RPC method null

I have a project with a service binding I call like this:
const result = await ctx.runtime.env.CRYPTO.encrypt(arg)
const result = await ctx.runtime.env.CRYPTO.encrypt(arg)
Despite the service being bound correctly, I ge this in production:
TypeError: ctx.runtime.env.CRYPTO.encrypt is not a function
TypeError: ctx.runtime.env.CRYPTO.encrypt is not a function
Logging this
console.log(
ctx.runtime.env.CRYPTO.fetch,
typeof ctx.runtime.env.CRYPTO.fetch,
ctx.runtime.env.CRYPTO.encrypt,
typeof ctx.runtime.env.CRYPTO.encrypt,
)
console.log(
ctx.runtime.env.CRYPTO.fetch,
typeof ctx.runtime.env.CRYPTO.fetch,
ctx.runtime.env.CRYPTO.encrypt,
typeof ctx.runtime.env.CRYPTO.encrypt,
)
Gives
"function fetch() { [native code] }",
"function",
null,
"undefined"
"function fetch() { [native code] }",
"function",
null,
"undefined"
I can rewrite it using fetch, but are these supposed to work?
4 Replies
xeon06
xeon06OP2mo ago
Although I will say, I was passing an object with array buffers in it and rewriting that with fetch is a bit annoying I'm able to confirm that fetch does work too, it's just the RPC methods that won't
dschewchenko
dschewchenko2mo ago
Hi. Check what is your compatibility date on both workers? must be at least 2024-04-03 on both workers Also your RPC worker class must extend WorkerEntrypoint
xeon06
xeon06OP2mo ago
@dschewchenko thank you so much, it was the compatibility date! It was too old! I'm very happy not to have to rewrite with fetch thanks again
dschewchenko
dschewchenko2mo ago
Welcome! Have a nice day :bibicat:
Want results from more Discord servers?
Add your server