Skip to content

Conversation

ItsWendell
Copy link
Contributor

@ItsWendell ItsWendell commented Mar 27, 2025

Fixes #508

Full disclosure (also see issue above):

I don't know why this issue occurs. I just found this fix by experimenting. In the original situation, the worker detects the handler as a 'Getter', but if you use the 'handler' getter the result is undefined, but only on 'cold' boots. In a warm worker the Getter is initialized and it just works. By changing how we export in handler.mjs to a named export, it no longer detects it as a Getter but as a async function and it now works properly on cold boots. If someone could explain why this happens, please do!

Copy link

changeset-bot bot commented Mar 27, 2025

🦋 Changeset detected

Latest commit: 6cd43ae

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@opennextjs/cloudflare Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

pkg-pr-new bot commented Mar 27, 2025

Open in Stackblitz

pnpm add https://pkg.pr.new/@opennextjs/cloudflare@509

commit: 6cd43ae

Copy link
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for the patch 🙏

I'm not sure if this is an ESBuild bug or not...
I'll try to reproduce on a simpler example.

But at least this fixes the issue for now 🎉

@vicb
Copy link
Contributor

vicb commented Mar 27, 2025

For ref, once thing that I tried is

      // @ts-expect-error: resolved by wrangler build
      const server = await import("./server-functions/default/handler.mjs");

      while (!server.handler) {
        await new Promise((resolve) => setTimeout(resolve, 0));
      }

It also fixes the issue. Meaning that await does not seem to work as expected...

@vicb vicb merged commit 42e2b5c into opennextjs:main Mar 27, 2025
7 checks passed
@ItsWendell
Copy link
Contributor Author

      while (!server.handler) {

Interesting! Do you know after how many event loops it resolves? Also tests run in wrangler's engine right? Interesting that it didn't catch this. Let me know if you figure out anything more, interesting to see what the core of the wildcard export / import issue is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] TypeError: handler3 is not a function

2 participants