Skip to content

Conversation

@kentonv
Copy link
Member

@kentonv kentonv commented Oct 11, 2025

Fixes #23

Per #23, many bundlers do not like our dynamic import of "cloudflare:workers". This PR takes a different approach, using the "exports" feature of "package.json" to point workerd at a different version of the code. That version imports "cloudflare:workers" and sticks it in the global scope before importing the rest of the library, thus allowing it to conditionally probe.

@threepointone is this a sane approach? I have very little understanding of JS tooling but this seem like it works.

Fixes #23

Per #23, many bundlers do not like our dynamic import of "cloudflare:workers". This PR takes a different approach, using the "exports" feature of "package.json" to point workerd at a different version of the code. That version imports "cloudflare:workers" and sticks it in the global scope before importing the rest of the library, thus allowing it to conditionally probe.
@kentonv kentonv requested a review from threepointone October 11, 2025 21:09
@threepointone
Copy link
Collaborator

Missed this, will see over the weekend

@scotthellewell
Copy link

This pull request fixes all the issues I was having. Any idea when it will be merged and a new package created?

@threepointone
Copy link
Collaborator

looking at it today

@kentonv
Copy link
Member Author

kentonv commented Oct 21, 2025

@scotthellewell Sorry for the delay on this and everything else Cap'n Web! In the month since Cap'n Web was released a whole lot of stuff has conspired to take of my time (and Sunil's too), and this week I'm on vacation. Next week I plan to circle back and address all the open Cap'n Web issues.

@scotthellewell
Copy link

@kentonv I hope you have a great vacation. I've grabbed your branch and compiled my own package from it for now which works. I just like to directly use from the npm repository when possible. But great library so far.

@aaronholla aaronholla mentioned this pull request Oct 22, 2025
Copy link
Collaborator

@threepointone threepointone left a comment

Choose a reason for hiding this comment

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

approving this because it works and I want to unblock, but I think we can simplify it. I'll work on that myself later.

@scotthellewell
Copy link

Awesome to see this is approved now. Do you have an estimate on when this will get merged and published to npm? I'd love to just reference your package, but I need this fix. If it will be a while still, I can publish a separate scoped npm package to use for the time being. But if it will be done in the next few days I would prefer to just wait. I would love an ETA. Thanks.

@kentonv
Copy link
Member Author

kentonv commented Oct 29, 2025

Yes I'm planning to do a pass through all the open issues tomorrow and then probably push a release.

Meant to do it yesterday but there was some other fire that came up. :/

@kentonv kentonv merged commit 3c499a1 into main Oct 30, 2025
4 checks passed
@kentonv kentonv deleted the kenton/fix-bundlers branch October 30, 2025 14:23
kentonv added a commit that referenced this pull request Nov 4, 2025
kentonv added a commit that referenced this pull request Nov 5, 2025
* Add changeset for past PR #82.

* Throw an error when attempting to access RpcTarget instance properties.

This helps people learn why instance properties are not accessible over RPC, whereas returning `undefined` leaves them confused.

Fixes #55

* Implement toString() for RpcStub and RpcPromise.

They just return `[object RpcStub]` and `[object RpcPromise]`, but that's better than the previous `[object Function]` which was confusing.

As suggested in #55.

* Fix type signature of newHttpBatchRpcSession().

An earlier version of the function was designed to have the same signature as `fetch()`, but when I added `RpcSessionOptions` it made more sense to make that the second param... but I only updated the implementation and forgot to update the type.

Fixes #67.

* Support serializing Infinity, -Infinity, and NaN.

Fixes #80

* Polyfill Promise.withResolvers().

This hopefully improves compatibility with old Safari versions and Hermes (React Native).

Unfortunately it didn't seem easy to extend the tests to cover React Native. There is a vitest-react-native package, but it looks little-used and unmaintained, so I didn't want to install it.

Might help with #91, though I won't declare that one "fixed" until we actually have tests proving it.

* Document missing expression types in protocol.md.

Fixes #48
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.

Many bundlers don't like the conditional import of "cloudflare:workers" and the top-level await

3 participants