Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.7.4 loads webworker types, breaking cloudflare workers types #1547

Closed
Cherry opened this issue Oct 5, 2023 · 2 comments
Closed

3.7.4 loads webworker types, breaking cloudflare workers types #1547

Cherry opened this issue Oct 5, 2023 · 2 comments
Labels

Comments

@Cherry
Copy link

Cherry commented Oct 5, 2023

What version of Hono are you using?

3.7.4

What runtime/platform is your app running on?

Cloudflare Workers

What steps can reproduce the bug?

Since version 3.7.4, Hono now includes /// <reference lib="webworker" /> in its output. (reference: e326208)

This is incompatible with Cloudflare Workers, since webworker defines crypto and other things with additional methods (see https://workers-types.pages.dev/#SubtleCrypto for example), and loading webworker types completely overrides these.

For example:

export default {
	async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
		const text1 = new TextEncoder().encode('Hello World');
		const text2 = new TextEncoder().encode('Hello World');
		if(crypto.subtle.timingSafeEqual(text1, text2)) {
			return new Response('Hello World!');
		}
		return new Response('Goodbye World!');
	},
};

(using tsconfig setup as defined at https://www.npmjs.com/package/@cloudflare/workers-types).

This works fine, and crypto.subtle.timingSafeEqual exists as expected.

The second that I import something from Hono though, like this:

import {Context} from 'hono';

export default {
	async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
		const text1 = new TextEncoder().encode('Hello World');
		const text2 = new TextEncoder().encode('Hello World');
		if(crypto.subtle.timingSafeEqual(text1, text2)) {
			return new Response('Hello World!');
		}
		return new Response('Goodbye World!');
	},
};

crypto is now overridden by webworker types, meaning the crypto.subtle.timingSafeEqual method doesn't exist, and I get an error like so:

src/index.ts:8:19 - error TS2339: Property 'timingSafeEqual' does not exist on type 'SubtleCrypto'.

8  if(crypto.subtle.timingSafeEqual(text1, text2)) {

What is the expected behavior?

webworker types should not be loaded in the case of cloudflare workers. The docs at https://www.npmjs.com/package/@cloudflare/workers-types call this out explicitly, since it has incompatibilities with Cloudflare Workers.

Additional information

Can we please get this rolled back or fixed? There are going to be so many other incompatibilities with loading webworker types in a Cloudflare Workers project - this is just one example.

@yusukebe
Copy link
Member

yusukebe commented Oct 5, 2023

@Cherry

Hi James. Thank you for the issues. I've released v3.7.5, which includes the fix now. If you try it, please let me know if it is fixed.

@Cherry
Copy link
Author

Cherry commented Oct 5, 2023

3.7.5 is working great now, thank you! Thanks for the very fast resolution 😃

@Cherry Cherry closed this as completed Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants