Skip to content

3.7.4 loads webworker types, breaking cloudflare workers types #1547

Closed
@Cherry

Description

@Cherry

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions