deploy_feedback icon indicating copy to clipboard operation
deploy_feedback copied to clipboard

Worker on deno deploy

Open hapaxlife opened this issue 3 years ago • 5 comments

We get

ReferenceError: Worker is not defined

when using a Worker

The following code is not working on Deno Deploy but working with Deno

import * as bcrypt from "https://deno.land/x/[email protected]/mod.ts";

console.log(  bcrypt.hashSync("test")) // OK
console.log( await bcrypt.hash("test")) // KO

hapaxlife avatar Feb 12 '22 09:02 hapaxlife

Same thing for me

I cannot hash user passwords server side for now

ninjinskii avatar May 20 '22 15:05 ninjinskii

Gonna look for this synchronous version by then

ninjinskii avatar May 20 '22 15:05 ninjinskii

Deno namespace is available in workers by default see https://deno.com/blog/v1.22

But we still have

ReferenceError: Worker is not defined
    at Module.hash (https://deno.land/x/[email protected]/src/main.ts:11:18)

However Deno tell us about worker in their blog

// This worker did NOT have access to the `Deno` namespace.
new Worker(new URL("./worker_without_deno.js", import.meta.url));

// This worker did have access to the `Deno` namespace.
new Worker(new URL("./worker_without_deno.js", import.meta.url), {
  deno: true,
});

hapaxlife avatar May 25 '22 06:05 hapaxlife

@hapaxlife I think the source of the confusion is that Deno Deploy does not support all of the APIs that Deno supports. I also ran into this and it took me a while to understand until I found the relevant documentation page.

This Deploy Docs API Reference page states:

Deno Deploy Runtime helps you write web servers in TypeScript/JavaScript using the Web APIs. It's different from Deno but aims to have similar APIs where applicable.

The following Web and Deno APIs are supported on Deno Deploy Runtime.

The Worker API is not listed, so it's not supported. I created an issue to improve the docs in that regard.

ttogola avatar Aug 04 '22 17:08 ttogola