# Trying to call an actor using agent-js from Cloudflare Workers

**URL:** <https://forum.dfinity.org/t/trying-to-call-an-actor-using-agent-js-from-cloudflare-workers/9915>\
**Category:** JavaScript\
**Created:** [December 25, 2021, 3:58pm UTC](https://forum.dfinity.org/t/trying-to-call-an-actor-using-agent-js-from-cloudflare-workers/9915 "2021-12-25T15:58:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![saikatdas0790](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/saikatdas0790/32/17147_2.png) [@saikatdas0790](https://forum.dfinity.org/u/saikatdas0790)\
**Post date:** [December 25, 2021, 3:58pm UTC](https://forum.dfinity.org/t/trying-to-call-an-actor-using-agent-js-from-cloudflare-workers/9915/1 "2021-12-25T15:58:47Z")

</div>

I’m trying to call an actor method from a Cloudflare worker but unable to make it start.

Cloudflare Workers supports a [service worker format and ES Modules](https://developers.cloudflare.com/workers/cli-wrangler/configuration#build) for the upload format. I’ve tried both but the import doesn’t work. I’ve use `dfx generate` to generate the declarations that I’m importing.

When trying the service worker format with type set to **webpack** , my code looks like this:

```auto
import { canisterId } from "../../src/declarations/backend";

addEventListener("fetch", (event) => {
  event.respondWith(handleRequest(event.request));
});
/**
 * Respond with hello worker text
 * @param {Request} request
 */
async function handleRequest(request) {
  console.log(canisterId);
  return new Response("Hello worker!", {
    headers: { "content-type": "text/plain" },
  });
}

```

The error i get is this:

![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/6/6b0e91c9048f8d8640ccdc2b111c853acadd39e3.png)

When I try the ES modules format, my code looks like this:

```auto
import { canisterId } from "../../src/declarations/backend";

export default {
  fetch(request) {
    console.log(canisterId);
    return new Response("Hello, world!", {
      headers: {
        "Content-Type": "text/plain",
      },
    });
  },
};

```

![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/2/2380ccda78f807035f4f40be46663114fb1d1a8e.png)

In the above examples, I was trying to import the actors first but to eliminate further, I’m just importing the canister ID string, but as shown above, the imports are making Cloudflare Workers choke.

Anyone manage to call their canister using agent-js from Cloudflare Workers?
