workers-rs icon indicating copy to clipboard operation
workers-rs copied to clipboard

`import shim from ". /shim.mjs"` worked fine on cloudflare pages a couple weeks ago, now I get `TypeError: an.fetch is not a function`

Open Jhonfunk opened this issue 9 months ago • 2 comments

import shim from "./shim.mjs"

export async function onRequest(context) {
  var rsp;
  try {
     rsp = shim.fetch(context.request, context.env, context);
  }
  catch(e) {
    return new Response("err:"+ e )
  }
  return rsp;
}

This code used to work fine on cloudflare pages, now it gets TypeError: An.fetch is not a function

Jhonfunk avatar May 14 '24 06:05 Jhonfunk

Which version of worker-build are you using? It sounds like Pages may not support the new WorkerEntrypoint interface introduced for RPC.

Edit: are you supplying a custom JavaScript entrypoint script?

kflansburg avatar May 14 '24 10:05 kflansburg

@kflansburg

Thanks.

After changing the version of worker-build back to 0.1.0 everything is fine.

Hopefully maybe the new WorkerEntrypoint interface could have some compatibility with the current Cloudflare Pages.

Jhonfunk avatar May 14 '24 11:05 Jhonfunk

@kflansburg

Thanks.

After changing the version of worker-build back to 0.1.0 everything is fine.

Hopefully maybe the new WorkerEntrypoint interface could have some compatibility with the current Cloudflare Pages.

What is the source of the code you included? Is Pages supplying that or are you using a custom entrypoint script? That may need to be updated to the new shim provided by worker-build

kflansburg avatar May 14 '24 11:05 kflansburg

I'm using this code as Cloudflare Pages Fucntions and it works fine with [email protected] + [email protected]

@kflansburg

Jhonfunk avatar May 14 '24 12:05 Jhonfunk

I'm using this code as Cloudflare Pages Fucntions and it works fine with [email protected] + [email protected]

@kflansburg

Yes, what I'm saying is that the bug may not be with Pages, but with the JavaScript you posted in your first message. Where did that come from?

kflansburg avatar May 14 '24 12:05 kflansburg

Yes, but where did the code in your first message come from? Is that your code? If so, you should update it to be compatible with the new interface.

kflansburg avatar May 14 '24 17:05 kflansburg

@kflansburg

After changing the version of worker-build back to 0.1.0 everything is fine.

Sorry, I wrote the wrong version number in this sentence. I actually switched back to version 0.0.10

You can compile the hello-world template to get index.wasm and shim.mjs then test it as Pages Functions using the code in myfirst message.

The problem occurs when you use [email protected] & [email protected]

Jhonfunk avatar May 14 '24 17:05 Jhonfunk

# Cargo.toml

worker = { version = "0.2.0" }
worker-macros = { version = "0.2.0" }
// ./functions/_middleware.js

import * as shim from "./shim.mjs"

moixllik avatar Aug 07 '24 04:08 moixllik

# Cargo.toml

worker = { version = "0.2.0" }
worker-macros = { version = "0.2.0" }
// ./functions/_middleware.js

import * as shim from "./shim.mjs"

Thanks bro

Jhonfunk avatar Aug 12 '24 06:08 Jhonfunk