Cannot file module '@cloudflare:workers'
Just created a new worker with wrangler and tried to
import { WorkerEntrypoint } from '@cloudflare:workers'
as shown on the docs site here: https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/#example--build-your-first-service-binding-using-rpc
But I get an error from TypeScript that it can't find the module:
Cannot find module '@cloudflare:workers' or its corresponding type declarations. typescript (2307) [2, 34]
And I also get an error from wrangler when I try to deploy it:
Has anyone run into this issue before? I would appreciate the help, thanks!Cloudflare Docs
Service bindings - Runtime APIs · Cloudflare Workers docs
Facilitate Worker-to-Worker communication.
18 Replies
What does your Worker look like?
this is the main function:
the doc seems to say
"cloudflare:workers"
not "@cloudflare:workers"
on the import, could that be causing it?:NotLikeThis:
^That, and if that doesn't work, try adding an
export default {};
at the bottomgood catch, sorry about that lol - damn, caught by one character
:lulujoy:
hrm, nevermind - LSP removed the error and then brought it back :/
the error did change though
now its just
Unable to resolve path to module 'cloudflare:workers'
and wrangler still gives the same error when I try to deployTry adding
export default {};
at the bottomso wrangler lets me deploy if I add this:
The error about being unable to resolve
cloudflare:workers
is still there though - not sure whydid u npm i?
yea
I dont think the solution is usable though, the test interface throws an error trying to use that worker now as a binding
Could not serialize object of type \"Fetcher\". This type does not support serialization.
- I think I'm going to have to retreat on trying to use the worker as RPCI wouldn’t expect that you’re able to pass stuff like env or ctx
Even requests I guess, since they have request.fetcher
maybe that's where the serialization errors are coming from, I'll refactor those objects out and retry
@s9tpepper Were you able to resolve "The error about being unable to resolve cloudflare:workers is still there though - not sure why"? If so how?
I think I solved it by upgrading "@Cloudflare/workers-types" to the latest version.
My
@cloudflare/workers-types
are at the latest version, but I can't seem to be able to import { DurableObject } from "cloudflare:workers";
:shrugg:did you resolve this @Chinoman10?
I might have this same issue:
Please do not reopen old threads. If you are having issues, please open a new thread instead