skymethod / denoflare Goto Github PK
View Code? Open in Web Editor NEWDevelop, test, and deploy Cloudflare Workers with Deno.
Home Page: https://denoflare.dev
License: MIT License
Develop, test, and deploy Cloudflare Workers with Deno.
Home Page: https://denoflare.dev
License: MIT License
Awesome project, I enjoy a lot.
Would be possible to configure the params like no-check in https://github.com/skymethod/denoflare/blob/54e1afabea7579fddb1070b5fcbe0ef20894c981/cli/deno_bundle.ts ?
Hi, I am getting the following error when doing : "denoflare serve main"
Compiling https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli-webworker/worker.ts into worker
contents...
Bundled https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli-webworker/worker.ts (process) in 105ms
runScript: /src/index.ts
Bundled /src/index.ts (process) in 38ms
worker: start
Error running script Error: Bad module.default: undefined
at Function.create (blob:null/4f3c49d7-43b6-4992-a2f6-11631123b713:578:49)
at async Function.start (blob:null/4f3c49d7-43b6-4992-a2f6-11631123b713:679:50)
at async blob:null/4f3c49d7-43b6-4992-a2f6-11631123b713:2781:22
at async RpcChannel.receiveMessage (blob:null/4f3c49d7-43b6-4992-a2f6-11631123b713:39:36)
at async self.onmessage (blob:null/4f3c49d7-43b6-4992-a2f6-11631123b713:2810:13)
error: Failed at the denoflare script
Deno 1.28.3
denoflare v0.5.11
scripts.ts:
export default {
"scripts": {
"denoflare": "deno run --unstable --allow-run --allow-write --allow-read --allow-net --allow-env https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli.ts"
}
};
.denoflare
{
"$schema": "https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/common/config.schema.json",
"scripts": {
"main": {
"path": "/src/index.ts",
"localPort": 3838
}
},
"profiles": {
"myprofile": {
"accountId": "xxxxxxxxxxxx",
"apiToken": "xxxxxxxxx"
}
}
}
index.ts
console.log('hello world');
some dependencies use top level await, which isn't supported in cloudflare worker, I with it can provide transpile support for it
Is this feature implemented?
I'm getting the error with the callstack:
error: Uncaught (in promise) TypeError: Deno.spawn is not a function
const rt = await Deno.spawn(command, options) as any;
^
at spawn (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.10/cli/spawn.ts:12:27)
at runDenoBundle (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.10/cli/deno_bundle.ts:67:53)
at denoBundle (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.10/cli/deno_bundle.ts:35:45)
at async bundle (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.10/cli/bundle.ts:104:35)
at async Function.start (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.10/cli/worker_manager.ts:38:43)
at async createLocalRequestServer (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.10/cli/cli_serve.ts:155:35)
at async Object.serve [as handler] (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.10/cli/cli_serve.ts:188:32)
at async CliCommand.routeSubcommand (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.10/cli/cli_command.ts:104:13)
at async https://raw.githubusercontent.com/skymethod/denoflare/v0.5.10/cli/cli.ts:33:5
When attempting to publish or serve any worker.
My specs
deno 1.32.4 (release, aarch64-apple-darwin)
v8 11.2.214.9
typescript 5.0.3
OS: Macbook Pro M1
I have a worker that's already deployed, can I connect to it through denoflare CLI?
Thank you.
Hi,
Seeing that there are config options for KV, I assumed denoflare supported it.
I gave it a simple test but get RpcKVNamespace.put not implemented.
Looking at the code, I see that get is partially implemented, but put, list, delete, etc are empty.
Is that correct?
Hi there, the public read has a couple of issues.
The second time you try to download a file you will recieve this error, the string will be different. I have tried this with multiple files. Status Code: 500
TypeError: Conditional ETag should not be wrapped in quotes ("d03c2f258e9fc6e7236f61c130ed1e48").
Range files, specifically m3u8 video files don't work.
Using this: denoflare push https://raw.githubusercontent.com/skymethod/denoflare/v0.5.4/examples/r2-public-read-worker/worker.ts
Hi,
This looks like an amazing project. Thanks in advance for taking it on and offering up.
I found denoflare while looking for worker script to make an R2 bucket public.
When I follow the example at: https://denoflare.dev/examples/r2-public-read
And, then create a .denoflare jsonc as explained there (but without a custom domain definition and WITH a directoryListing flag) and then do denoflare serve <my-worker-name>
I get a "There is nothing here yet" page.
My R2 bucket has only one '/media' directory in it with many images under it.
So, if I got to https://..workers.dev/media/ I also get the "There is nothing here yet" page.
However, if I run locally with denoflare server <my-worker-name>
, the http://localhost:8080/ says "file not found"
BUT, the http://localhost:8080/media/ does work and shows the image file.
Is it maybe a configuration error?
I've browsed through the denoflare CLI code for serve
and I'm not sure where exactly this would be enabled. It would be so amazing to be able to hit breakpoints inside the worker, similar to what is mentioned here for deno --inspect: https://deno.land/manual/getting_started/debugging_your_code
I tried to find information about if Denoflare supports Pages + Functions combination. I didn't find any command, so now I am asking is that supported?
https://developers.cloudflare.com/pages/platform/functions/
Module-based Cloudflare workers that use no environment bindings to cf-specific services (or have graceful fallbacks) basically work unmodified on Deno Deploy.
With an entry point wrapper along the lines of:
import { serve } from 'https://deno.land/[email protected]/http/server.ts';
import { default as worker } from './worker.ts'; // the cloudflare module-based worker entry point
serve((req, init) => {
const env = Deno.env.toObject();
if (init.remoteAddr.transport === 'tcp') {
const newHeaders = new Headers(req.headers);
newHeaders.append('cf-connecting-ip', init.remoteAddr.hostname);
req = new Request(req, { headers: newHeaders });
}
return worker.fetch(req, env);
});
Since Deploy has an api deployment option, we should add Deploy as a target option and generate this entrypoint wrapper automatically.
We are attempting to combine Kian's s3-to-r2 worker and denoflare's r2-presigned-url worker.
We have implemented a simple worker based on Kian's that first calls the r2-presigned-url worker's fetch()
method before doing it's thing.
We are unable to denoflare push
this worker to CloudFlare and have narrowed the cause down to a minimal worker to demonstrate the issue:
import { AwsClient } from "aws4fetch";
export default {
async fetch(request: Request): Promise<Response> {
return new Response()
}
}
The error is:
$ denoflare push hello-local \
--account-id "$CF_ACCOUNT_ID" \
--api-token "$CF_API_TOKEN" \
--custom-domain "$WORKER_BUCKET_NAME.$WORKER_ENDPOINT" \
--name "$WORKER_NAME"
bundling FOO-r2-presigned-url-worker into bundle.js...
bundle finished (process) in 38ms
computed bindings in 0ms
putting module-based worker FOO-r2-presigned-url-worker... (0bytes) (20bytes compressed)
error: Uncaught (in promise) Error: putScript failed: status=400, errors=10068 The uploaded script has no registered event handlers.
{ code: 10068, message: "The uploaded script has no registered event handlers." }
at execute (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/common/cloudflare_api.ts:1343:15)
at async putScript (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/common/cloudflare_api.ts:97:13)
at async buildAndPutScript (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli_push.ts:86:9)
at async Object.push [as handler] (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli_push.ts:120:5)
at async CliCommand.routeSubcommand (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli_command.ts:104:13)
at async https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli.ts:33:5
If we comment out the AwsClient
import, it is able to deploy:
$ denoflare push hello-local \
--account-id "$CF_ACCOUNT_ID" \
--api-token "$CF_API_TOKEN" \
--custom-domain "$WORKER_BUCKET_NAME.$WORKER_ENDPOINT" \
--name "$WORKER_NAME"
bundling FOO-r2-presigned-url-worker into bundle.js...
bundle finished (process) in 35ms
computed bindings in 0ms
putting module-based worker FOO-r2-presigned-url-worker... (262bytes) (188bytes compressed)
put script FOO-r2-presigned-url-worker in 807ms
ensuring FOO points to FOO-r2-presigned-url-worker...
bound worker to custom domain in 743ms
Kian's original script uses aws4fetch
, so we need that. denoflare push
fails with the same error on Kian's original script.
We can deploy Kian's original script with wrangler, but we can't import and use the denoflare r2-presigned-url worker code because CloudFlare then claims the module doesn't exist. Kian on Discord says "Wrangler wouldn't bundle URL imports, it just uses esbuild"
We found #38 (comment) and we tried adding isolationLevel: "none"
to the config and switched to denoflare serve
which yielded a different error:
$ denoflare serve hello-local
error: Uncaught (in promise) TypeError: Relative import path "index2.ts" not prefixed with / or ./ or ../ from "https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/common/module_worker_execution.ts"
const module = await import(scriptPath);
^
at async Function.create (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/common/module_worker_execution.ts:19:24)
at async Function.start (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/common/worker_execution.ts:39:50)
at async createLocalRequestServer (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli_serve.ts:154:20)
at async Object.serve [as handler] (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli_serve.ts:190:32)
at async CliCommand.routeSubcommand (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli_command.ts:104:13)
We tried switching to an absolute path, but it seems to want to combine that absolute (or relative) path with a GitHub URL that doesn't work:
$ denoflare serve hello-local
Download https://raw.githubusercontent.com/Users/FOO/cloudflare-worker-s3-to-r2-migration/src/index2.ts
error: Uncaught (in promise) TypeError: Module not found "https://raw.githubusercontent.com/Users/FOO/cloudflare-worker-s3-to-r2-migration/src/index2.ts".
const module = await import(scriptPath);
^
at async Function.create (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/common/module_worker_execution.ts:19:24)
at async Function.start (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/common/worker_execution.ts:39:50)
at async createLocalRequestServer (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli_serve.ts:154:20)
at async Object.serve [as handler] (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli_serve.ts:190:32)
at async CliCommand.routeSubcommand (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli_command.ts:104:13)
at async https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli/cli.ts:33:5
We were also unsuccessful in an attempt to locate the bundle.js
file that is supposedly built, so we can see what has happened and why it no longer has any registered event handlers.
I'm not sure what else to try now except build a version of denoflare that uses local/relative import paths that are compatible with wrangler?
Hello,
a few days ago I created a simple CDN with denoflare and cloudflare r2. But today the r2 request failed with the error: Error servicing request Error: Expected content-length header
Error servicing request Error: Expected content-length header
at getExpectedHeader (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/cli/api_r2_bucket.ts:180:11)
at new HeadersBasedR2Object (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/cli/api_r2_bucket.ts:236:22)
at new ResponseBasedR2ObjectBody (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/cli/api_r2_bucket.ts:268:9)
at ApiR2Bucket.get (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/cli/api_r2_bucket.ts:61:16)
at async https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/common/rpc_r2_bucket.ts:39:67
at async RpcChannel.receiveMessage (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/common/rpc_channel.ts:41:36)
at async Worker.worker.onmessage (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/cli/worker_manager.ts:67:17)
This error is only happen when the requested file actually exists on the r2 bucket.
I tried to replace the api key with a new one but the error still happen.
Is this a known issue or am I doing something wrong?
main.ts
export default {
fetch: async (
req: IncomingRequestCf,
env: WorkerEnvironment,
ctx: ModuleWorkerContext
): Promise<Response> => {
const file = await env.bucket.get('assets/logo.svg');
return new Response('ok');
},
};
export interface WorkerEnvironment {
bucket: R2Bucket;
}
.denoflare
{
"$schema": "https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/common/config.schema.json",
"scripts": {
"cdn": {
"path": "./modules/cdn/main.ts",
"localPort": 8081,
"bindings": {
"bucket": {
"bucketName": "storage"
}
}
}
},
"profiles": {
"default": {
"default": true,
"accountId": "xxx",
"apiToken": "xxx"
}
}
}
This is less a bug/issue of denoflare as it is a "why tho" on part of Cloudflare.
The D1 Runtime API does not actually exist on the Cloudflare Servers right now.
What wrangler does when you have a D1 Binding is prefix the whoooole thing with some fun static text and then include this mess:
https://github.com/cloudflare/wrangler2/blob/8986ccb3eb285f5a50cdd987d5e17f9eb6df3480/packages/wrangler/templates/d1-beta-facade.js
Making it the new script entry point after replacing the variable in it.
If you want to support D1 bindings magically, you'll have to bundle this file with in the denoflare build process. Which sounds like a lot of pain that can be avoided.
I think it'll be easier to just add a blurb to the docs until Cloudflare decides to actually publish a D1 Runtime API to their servers.
While denoflare serve looks into the ENV or the flags for my account-id and api-token, the push command won't see the same ENV vars or flags.
Here is the code who produce the error:
error: Uncaught (in promise) Error: putScript failed: status=400, errors=10068 The uploaded script has no registered event handlers.
export default {
async fetch(request: Request): Promise<Response> {
// fake await to simulate a slow response
await new Promise(resolve => setTimeout(resolve, 1000))
return new Response('Hello, world!')
},
}
The code without async work at upload.
The code with async work in Cloudflare workers, so it should be allowed in Denoflare.
Did we have Github Actions
support? or maybe an example/tuts for how to do this.
I can see https://github.com/cloudflare/wrangler-action but not sure that I need to tweak some or it's just work for denoflare.
Great project btw.
Does Denoflare support Workers Sites (ie publishing static assets alongside a workers script)?
It's possible to use the API the same way done for AWS to deploy:
https://docs.netlify.com/api/get-started/#deploy-with-the-api
The same code of https://github.com/Cap-go/capgo
is already deployed in Cloudflare, Supabase egde and Netlify edge, but with transform script.
Now with deno support npm prefix I can delete all my transform code if we can netlify deploy
I'm not sure how unusual this is, but I have a use case for range headers on HEAD
requests - the duckdb-wasm library can do partial reads on files, and it uses a HEAD request with a range of bytes=0-
to check whether partial reads are supported. The current worker only computes the range for GET
requests. Simply removing the conditional makes it work as expected:
let range = tryParseRange(headers);
It would be very useful for d1 application
Thank you for this lovely code!
I am following this link https://examples.deno.land/dependency-management & it is not working yet, any idea why please?!
It's impossible to use Response.statusText
as it's not implemented:
Thank you for creating this!
I run denoflare serve hello-local
& the result is
Compiling https://raw.githubusercontent.com/skymethod/denoflare/v0.4.5/cli-webworker/worker.ts into worker contents...
error: Uncaught (in promise) TypeError: Deno.emit is not a function
const result = await Deno.emit(rootSpecifier, {
^
at emit (https://raw.githubusercontent.com/skymethod/denoflare/v0.4.5/cli/emit.ts:3:31)
at Function.start (https://raw.githubusercontent.com/skymethod/denoflare/v0.4.5/cli/worker_manager.ts:30:32)
at createLocalRequestServer (https://raw.githubusercontent.com/skymethod/denoflare/v0.4.5/cli/cli_serve.ts:122:55)
at serve (https://raw.githubusercontent.com/skymethod/denoflare/v0.4.5/cli/cli_serve.ts:155:38)
at async https://raw.githubusercontent.com/skymethod/denoflare/v0.4.5/cli/cli.ts:16:13
Now that workerd is working reasonably well:
https://github.com/cloudflare/workerd
Should we add support to be able to start/watch it in the same way wrangler dev --experimental-local
does? Since the APIs are emulated the same, it shouldn't matter if its deno or node style post-bundling using this worker.
The cloudflare typings for the fetch seems to be different in cloudflare:
Example:
let response = await fetch(request, {
cf: {
// Always cache this fetch regardless of content type
// for a max of 5 seconds before revalidating the resource
cacheTtl: 5,
cacheEverything: true,
//Enterprise only feature, see Cache API for other plans
cacheKey: someCustomKey,
},
});```
In deno the following error occurs:
No overload matches this call.
Overload 1 of 2, '(input: string | URL | Request, init?: RequestInit | undefined): Promise', gave the following error.
Argument of type '{ cf: RequestInitCfProperties; }' is not assignable to parameter of type 'RequestInit'.
Object literal may only specify known properties, and 'cf' does not exist in type 'RequestInit'. Overload 2 of 2, '(input: string | URL | Request, init?: (RequestInit & { client: HttpClient; }) | undefined): Promise', gave the following error.
Argument of type '{ cf: RequestInitCfProperties; }' is not assignable to parameter of type 'RequestInit & { client: HttpClient; }'.
Object literal may only specify known properties, and 'cf' does not exist in type 'RequestInit & { client: HttpClient; }'.deno-ts(2769)```
Error: packRequest: init.signal
at packRequest (blob:null/74878e83-1a35-4f3c-a67a-93d94adee03e:1003:50)
at blob:null/74878e83-1a35-4f3c-a67a-93d94adee03e:765:22
at fetchWithTimeout (blob:null/b9119e73-2aec-4ae2-bd38-1b596890bc68:32228:28)
at fallback (blob:null/b9119e73-2aec-4ae2-bd38-1b596890bc68:32263:29
Code to reproduce:
async function fetchWithTimeout(resource: RequestInfo, options: RequestOptions = {}): Promise<Response> {
const controller = new AbortController()
console.log('fetch', resource)
const { timeout = 5000 } = options
console.log('timeout', timeout)
const id = setTimeout(() => {
console.log('timeout')
controller.abort()
}, timeout)
const response = await fetch(resource, {
signal: controller.signal,
})
clearTimeout(id)
return response
}
Line causing: here
first of all thanks for such amazing project, but I don't find a reference to see how can I configure my worker to use triggers.
The documentation says to install with --unstable
, but as of Deno 1.40 this now results in a warning upon each use.
The `--unstable` flag is deprecated and will be removed in Deno 2.0. Use granular `--unstable-*` flags instead.
Learn more at: https://docs.deno.com/runtime/manual/tools/unstable_flags
I installed without --unstable
and it seems to be working OK, which unstable features are used exactly? Couldn't determine in a quick perusal. (Deno reference and available flags here: https://docs.deno.com/runtime/manual/tools/unstable_flags)
When creating the denoflare configuration while referring to the schema https://raw.githubusercontent.com/skymethod/denoflare/v0.5.10/common/config.schema.json
suggested in the denoflare configuration (https://denoflare.dev/cli/configuration), we cannot bind a service to our configuration in the bindings
section. The only options proposed are in the image attached.
Is there something we are missing in order to bind a worker to another service?
Hi. I'm interested in using this project, but the documentation puzzles me. There is no clear path from installation to running and deploying a worker.
Why do I need to define my projects in the .denoconfig
file in the home folder? Isn't it more intuitive to create a config file at the root of the project?
When running a script via denoflare serve
, error stracktraces don't have source file path:
Error servicing request Error: DenoflareResponse.statusText not implemented
at DenoflareResponse.get statusText (blob:null/479bbc34-2f8a-4e03-9c0c-6e2cb57f332e:479:15)
at WorkerRouter.#fireError (blob:null/2f968119-42b1-4463-a069-f31f715a2813:774:78)
at WorkerRouter.#route (blob:null/2f968119-42b1-4463-a069-f31f715a2813:768:28)
at Object.fetch (blob:null/2f968119-42b1-4463-a069-f31f715a2813:958:27)
at ModuleWorkerExecution.fetch (blob:null/479bbc34-2f8a-4e03-9c0c-6e2cb57f332e:629:34)
at WorkerExecution.fetch (blob:null/479bbc34-2f8a-4e03-9c0c-6e2cb57f332e:727:34)
at blob:null/479bbc34-2f8a-4e03-9c0c-6e2cb57f332e:3107:41
at RpcChannel.receiveMessage (blob:null/479bbc34-2f8a-4e03-9c0c-6e2cb57f332e:39:42)
at self.onmessage (blob:null/479bbc34-2f8a-4e03-9c0c-6e2cb57f332e:3146:30)
at wrappedHandler (ext:deno_web/02_event.js:1401:12)
How to reproduce:
Expected Result:
From testing this in WSL, it should just automagically work.
Actual Result:
Under Windows, probably due to the whole \ instead of / thing. You get a broken import ("filefile.txt" does not exist).
It works perfectly fine if the script and file are in the same subfolder though.
i follow you tutorial https://denoflare.dev/guides/serve
and i serve project
but get error message
Error running script Error: Bad module.default: undefined
at Function.create (blob:null/748eb05c-fe5c-4070-a880-9bcb5cfeae9b:573:49)
at async Function.start (blob:null/748eb05c-fe5c-4070-a880-9bcb5cfeae9b:672:50)
at async blob:null/748eb05c-fe5c-4070-a880-9bcb5cfeae9b:2504:22
at async RpcChannel.receiveMessage (blob:null/748eb05c-fe5c-4070-a880-9bcb5cfeae9b:39:36)
at async self.onmessage (blob:null/748eb05c-fe5c-4070-a880-9bcb5cfeae9b:2532:13)
my .denoflare file
{
"$schema": "https://raw.githubusercontent.com/skymethod/denoflare/v0.5.7/common/config.schema.json",
"scripts": {
"hello-local": {
"path": "main.ts",
"localPort": 3030
}
},
"profiles": {
"account1": {
// your cloudflare account id
"accountId": "6b9a6f27ffddd42d8f9b0f16d655e7fe",
// your cloudflare api token
"apiToken": "CxRhXkwP35y0rKm5fjJ2_eIiWjkalz8Z8t7Pb-yE"
}
}
}
With the following test.js
, denoflare won't start.
% cat test.js
export default {
async fetch (request, env) {
return new Response ('hello\n');
},
};
% ../bin/denoflare serve test.js
Compiling https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli-webworker/worker.ts into worker contents...
✅ Granted write access to "/var/folders/dl/2c03sbp56t3djlcsq246h9v80000gn/T/".
Bundled https://raw.githubusercontent.com/skymethod/denoflare/v0.5.11/cli-webworker/worker.ts (process) in 1219ms
runScript: test.js
worker: start
Error running script Error: Script did not add a fetch listener
at Function.create (blob:null/13008441-80e2-4428-9ef9-bead231069a1:614:48)
at async Function.start (blob:null/13008441-80e2-4428-9ef9-bead231069a1:679:125)
at async blob:null/13008441-80e2-4428-9ef9-bead231069a1:2781:22
at async RpcChannel.receiveMessage (blob:null/13008441-80e2-4428-9ef9-bead231069a1:39:36)
at async self.onmessage (blob:null/13008441-80e2-4428-9ef9-bead231069a1:2810:13)
.ts files works fire, however. Seems plain .js files are not supported.
Trying to use import maps to replace my deps.ts file.
https://deno.land/[email protected]/npm_nodejs/import_maps
Works just fine with deno run, however when I use denoflare I get an export module undefined
. It appears it is ignoring my deno.jsonc
?
I'd like to begin using Denoflare but with a lack of experience using Deno, I'm lost after finishing the Hello World tutorial. It would be great if there were a few more tutorials that took users to the next step after Hello World. I was the first person to use the denoflare
tag on Stack Overflow so I couldn't find much help there either. Here is my question on Stack Overflow:
But the issue here is a request for more beginner documentation. Thank you for your work on this project.
I try to push hello-wasm-worker
, but I couldn't with the error putScript raised.
I seem importWasm
function cause this error, but I couldn't understand the details...
bundling test-wasm-worker into bundle.js...
bundle finished (process) in 361ms
computed bindings in 1ms
putting module-based worker test-wasm-worker... (38.2kb) (6.3kb compressed)
error: Uncaught (in promise) Error: putScript failed: status=400, errors=10021 Uncaught Error: Some functionality, such as asynchronous I/O, timeouts, and generating random values, can only be performed while handling a request.
at line 0
{
code: 10021,
message: "Uncaught Error: Some functionality, such as asynchronous I/O, timeouts, and generating random values..."
}
at execute (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/common/cloudflare_api.ts:1044:15)
at async putScript (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/common/cloudflare_api.ts:96:13)
at async buildAndPutScript (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/cli/cli_push.ts:83:9)
at async Object.push [as handler] (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/cli/cli_push.ts:117:5)
at async CliCommand.routeSubcommand (https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/cli/cli_command.ts:104:13)
at async https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/cli/cli.ts:33:5
denoflare push test-wasm-worker --config .denoflare.jsonc --account-id $CLOUDFLARE_ACCOUNT_ID --api-token $CLOUDFLARE_API_TOKEN
{
// This jsonc file supports comments and trailing commas!
// optional schema to get auto-completions when editing this file in vscode, etc
"$schema": "https://raw.githubusercontent.com/skymethod/denoflare/v0.5.3/common/config.schema.json",
// define script configurations by name, and their associated bindings and options
// you can then simply refer to them by name in your denoflare commands
// note the same script source can be specified more than once with different configurations (local vs prod etc)
"scripts": {
"test-wasm-worker": {
"path": "hello.ts",
"localPort": 3002
}
}
}
I'm trying denoflare for cf worker development and having issues with the type definitions. The official type definition file does not play with deno as it contains many conflicting definitions.
I have found this file in the repo but it seems to be different from the official definitions. For example, the get
method of KVNamespace
can be used with only 1 argument but raises type error when using the definition from this file.
I wonder what's the recommended / common practice here. Thanks.
When I try to fetch using body, e.g.
await fetch("https://site...", {
"method": "POST",
"body": JSON.stringify({})
})
throw this:
catch Error: packRequest: init.body
at packRequest (blob:null/3639bbfb-e6a4-4dca-8f3f-dd8a1a3c8f00:923:48)
at blob:null/3639bbfb-e6a4-4dca-8f3f-dd8a1a3c8f00:720:22
at apo (blob:null/09d901da-479f-4908-9df0-1021d32d744e:7:25)
at serveTitle (blob:null/09d901da-479f-4908-9df0-1021d32d744e:4557:25)
at async Object.fetch (blob:null/09d901da-479f-4908-9df0-1021d32d744e:4569:28)
at async ModuleWorkerExecution.fetch (blob:null/3639bbfb-e6a4-4dca-8f3f-dd8a1a3c8f00:584:16)
at async WorkerExecution.fetch (blob:null/3639bbfb-e6a4-4dca-8f3f-dd8a1a3c8f00:682:16)
at async blob:null/3639bbfb-e6a4-4dca-8f3f-dd8a1a3c8f00:2619:30
at async RpcChannel.receiveMessage (blob:null/3639bbfb-e6a4-4dca-8f3f-dd8a1a3c8f00:39:36)
at async self.onmessage (blob:null/3639bbfb-e6a4-4dca-8f3f-dd8a1a3c8f00:2656:13)
Now that Denoflare's core functionality has been stable for some time, we should start attaching a single-binary version to each release, for folks that don't have Deno installed locally, or would just rather have a single binary.
Unfortunately, we can't do this until deno compile gets webworker support, since denoflare serve
(in isolate mode, the default) uses a permissionless web worker for hot reloading.
The r2-presigned-url-worker
example looks like exactly what I need (thanks!) to implement a worker that retains the existing presigned URL authorization functionality on a private bucket. But I am unable to run it locally via deno serve
or publish it example to CloudFlare.
Steps:
brew install deno
per docsdeno install --unstable --allow-read --allow-net --allow-env --allow-run --name denoflare --force https://raw.githubusercontent.com/skymethod/denoflare/v0.5.8/cli/cli.ts
per docs
https://raw.githubusercontent.com/skymethod/denoflare/master/cli/cli.ts
git clone https://github.com/skymethod/denoflare.git
and cd to denoflare/examples/r2-presigned-url-worker
.denoflare
file per docs, but with "path": "worker.ts"
instead of "path": "index.ts"
, and provide accountId
and apiToken
denoflare serve hello-local
I get this error:
$ denoflare serve hello-local
Compiling https://raw.githubusercontent.com/skymethod/denoflare/31db528115dc6260ac09ba2abd6c9a5aa8709b8a/cli-webworker/worker.ts into worker contents...
✅ Granted write access to "/var/folders/2j/ymfzssrx66gg87hypqbw1ptr0000gn/T/".
Bundled https://raw.githubusercontent.com/skymethod/denoflare/31db528115dc6260ac09ba2abd6c9a5aa8709b8a/cli-webworker/worker.ts (process) in 15413ms
runScript: worker.ts
Bundled worker.ts (process) in 547ms
worker: start
Error running script TypeError: Cannot set property caches of #<DedicatedWorkerGlobalScope> which has only a getter
at defineGlobalCaches (blob:null/e6ae24c2-3357-4eff-bd5d-36a8a43a5ebd:507:33)
at defineModuleGlobals (blob:null/e6ae24c2-3357-4eff-bd5d-36a8a43a5ebd:490:5)
at Function.create (blob:null/e6ae24c2-3357-4eff-bd5d-36a8a43a5ebd:557:9)
at Function.start (blob:null/e6ae24c2-3357-4eff-bd5d-36a8a43a5ebd:674:78)
at blob:null/e6ae24c2-3357-4eff-bd5d-36a8a43a5ebd:2561:44
at RpcChannel.receiveMessage (blob:null/e6ae24c2-3357-4eff-bd5d-36a8a43a5ebd:39:42)
at self.onmessage (blob:null/e6ae24c2-3357-4eff-bd5d-36a8a43a5ebd:2589:30)
at wrappedHandler (deno:ext/web/02_event.js:1362:14)
at innerInvokeEventListeners (deno:ext/web/02_event.js:755:9)
at invokeEventListeners (deno:ext/web/02_event.js:795:7)
I also tried to take an existing worker (kian's s3-to-r2-migration which is already working (but allows public access) and import the r2-presigned-url-worker
example so that I could first execute your computeResponse()
and fallback to kian's code:
import r2PresignedUrlWorker from "https://raw.githubusercontent.com/skymethod/denoflare/master/examples/r2-presigned-url-worker/worker.ts";
...
export default {
async fetch(request: Request, env: Env, ctx: EventContext<any, any, any>): Promise<Response> {
const response = await r2PresignedUrlWorker.fetch(request, env);
if (response.status == 200) {
return response;
}
... fallback to kian's code
But when I try to publish this:
$ wrangler publish
⛅️ wrangler 2.1.10
--------------------
Your worker has access to the following bindings:
- R2 Buckets:
- R2: ...
- Vars:
- AWS_DEFAULT_REGION: "auto"
- AWS_S3_BUCKET: "..."
- AWS_S3_BUCKET_SCHEME: "https:"
- AWS_SERVICE: "s3"
Total Upload: 15.42 KiB / gzip: 4.56 KiB
✘ [ERROR] A request to the Cloudflare API (/accounts/.../workers/scripts/s3-to-r2) failed.
Uncaught Error: No such module
"https:/raw.githubusercontent.com/skymethod/denoflare/master/examples/r2-presigned-url-worker/worker.ts".
imported from "index.js"
[code: 10021]
If you think this is a bug, please open an issue at:
https://github.com/cloudflare/wrangler2/issues/new/choose
Can you please provide some guidance on how to run and publish this example as-is, and how I might import and use it within an existing worker?
In my Deno grammY application, when I call apiThrottler function from @grammyjs/transformer-throttler package, and run $ denoflare serve src/prod-cloudflare.ts
, I've got the following error:
Error running script SyntaxError: Identifier 'concat' has already been declared at blob:null/fc6d65b1-68e1-4492-9180-8f3271ba2cd7:824:1
at async Function.create (blob:null/f2d9e371-4eb3-4dc9-8976-db324eb14fef:563:24)
at async Function.start (blob:null/f2d9e371-4eb3-4dc9-8976-db324eb14fef:679:50)
at async blob:null/f2d9e371-4eb3-4dc9-8976-db324eb14fef:2781:22
at async RpcChannel.receiveMessage (blob:null/f2d9e371-4eb3-4dc9-8976-db324eb14fef:39:36)
at async self.onmessage (blob:null/f2d9e371-4eb3-4dc9-8976-db324eb14fef:2810:13)
Context:
But, on Node.js, and using it (@grammyjs/transformer-throttler) via NPM – it works OK (it means I don't get this error).
calling import()
in ModuleWorkerExecution.create
hangs indefinately starting in deno v1.34.2 when using importText
, importBinary
, or importWasm
Workaround for now is to stay on Deno v1.34.1.
Looks to be a possible Deno regression, as the entire module appears to be loaded and init successfully, including fetched resources over rpc (importX
calls are translated to fetches when not on Cloudflare), just never returns to the caller.
Will look to create a small repro case and send over to the Deno folks.
how to Passing in environment variables into .denoflare
I have a index.js
script which imports postgres drivers:
import { Client, Pool } from "https://deno.land/x/postgres/mod.ts";
When running I get:
mlanza@Marios-MacBook-Air df-ex % denoflare serve hello-local
Compiling https://raw.githubusercontent.com/skymethod/denoflare/v0.3.3/cli-webworker/worker.ts into worker contents...
Compiled https://raw.githubusercontent.com/skymethod/denoflare/v0.3.3/cli-webworker/worker.ts into worker contents in 630ms
runScript: index.js
worker: start
Error running script TypeError: Requires net access to "deno.land", run again with the --allow-net flag
at blob:null/33e03125-26c1-4b7b-88c2-5e4888b766d3:1:30
at async Function.create (blob:null/2b6f1dc4-863b-4125-87f2-b6f05e8dcbbb:428:9)
at async Function.start (blob:null/2b6f1dc4-863b-4125-87f2-b6f05e8dcbbb:496:125)
at async blob:null/2b6f1dc4-863b-4125-87f2-b6f05e8dcbbb:1547:22
at async RpcChannel.receiveMessage (blob:null/2b6f1dc4-863b-4125-87f2-b6f05e8dcbbb:34:36)
at async self.onmessage (blob:null/2b6f1dc4-863b-4125-87f2-b6f05e8dcbbb:1587:13)
This was after confirming that serving using the vanilla .ts example worked. I am using .js. I tried passing in the --allow-net
flag myself but I'm not sure the baton got passed.
I ignored the local failure and trudged on:
mlanza@Marios-MacBook-Air df-ex % denoflare push hello-local
bundling hello-local into bundle.js...
Download https://deno.land/x/postgres/mod.ts
Warning Implicitly using latest version (v0.14.2) for https://deno.land/x/postgres/mod.ts
Download https://deno.land/x/[email protected]/mod.ts
Download https://deno.land/x/[email protected]/client.ts
Download https://deno.land/x/[email protected]/client/error.ts
Download https://deno.land/x/[email protected]/connection/connection_params.ts
Download https://deno.land/x/[email protected]/pool.ts
Download https://deno.land/x/[email protected]/query/query.ts
Download https://deno.land/x/[email protected]/query/transaction.ts
Download https://deno.land/x/[email protected]/connection/message.ts
Download https://deno.land/x/[email protected]/query/decode.ts
Download https://deno.land/x/[email protected]/query/encode.ts
Download https://deno.land/x/[email protected]/utils/utils.ts
Download https://deno.land/x/[email protected]/utils/deferred.ts
Download https://deno.land/x/[email protected]/connection/connection.ts
Download https://deno.land/x/[email protected]/connection/packet.ts
Download https://deno.land/x/[email protected]/deps.ts
Download https://deno.land/x/[email protected]/query/decoders.ts
Download https://deno.land/x/[email protected]/query/oid.ts
Download https://deno.land/x/[email protected]/connection/auth.ts
Download https://deno.land/x/[email protected]/connection/message_code.ts
Download https://deno.land/x/[email protected]/connection/scram.ts
Download https://deno.land/x/[email protected]/query/array_parser.ts
Download https://deno.land/x/[email protected]/query/types.ts
Download https://deno.land/[email protected]/async/mod.ts
Download https://deno.land/[email protected]/bytes/mod.ts
Download https://deno.land/[email protected]/datetime/mod.ts
Download https://deno.land/[email protected]/encoding/base64.ts
Download https://deno.land/[email protected]/fmt/colors.ts
Download https://deno.land/[email protected]/hash/mod.ts
Download https://deno.land/[email protected]/hash/sha256.ts
Download https://deno.land/[email protected]/io/buffer.ts
Download https://deno.land/[email protected]/async/deadline.ts
Download https://deno.land/[email protected]/async/debounce.ts
Download https://deno.land/[email protected]/async/deferred.ts
Download https://deno.land/[email protected]/async/delay.ts
Download https://deno.land/[email protected]/async/mux_async_iterator.ts
Download https://deno.land/[email protected]/async/pool.ts
Download https://deno.land/[email protected]/async/tee.ts
Download https://deno.land/[email protected]/datetime/formatter.ts
Download https://deno.land/[email protected]/bytes/equals.ts
Download https://deno.land/[email protected]/bytes/bytes_list.ts
Download https://deno.land/[email protected]/io/types.d.ts
Download https://deno.land/[email protected]/hash/_wasm/hash.ts
Download https://deno.land/[email protected]/hash/hasher.ts
Download https://deno.land/[email protected]/datetime/tokenizer.ts
Download https://deno.land/[email protected]/encoding/hex.ts
Download https://deno.land/[email protected]/hash/_wasm/wasm.js
bundle finished in 1444ms
computed bindings in 0ms
putting script hello-local... (328.9kb) (93.7kb compressed)
error: Uncaught (in promise) Error: putScript failed: status=400, errors=10021 Uncaught ReferenceError: FinalizationRegistry is not defined
at line 0
at execute (https://raw.githubusercontent.com/skymethod/denoflare/v0.3.3/common/cloudflare_api.ts:164:15)
at async putScript (https://raw.githubusercontent.com/skymethod/denoflare/v0.3.3/common/cloudflare_api.ts:40:13)
at async buildAndPutScript (https://raw.githubusercontent.com/skymethod/denoflare/v0.3.3/cli/cli_push.ts:52:9)
at async push (https://raw.githubusercontent.com/skymethod/denoflare/v0.3.3/cli/cli_push.ts:60:5)
at async https://raw.githubusercontent.com/skymethod/denoflare/v0.3.3/cli/cli.ts:15:13
I tried to deploy another version of the same script using wrangler
and it failed to resolve and bundle all the webpack
deps. I never got it working. I got the script, same import, working on Deno Deploy in short order so I know it's conceptually sound.
I am trying to repeat that success on Cloudflare's platform using your tool. I am excited about it. Having a simple tool for bundling/deploying ES modules directly to Cloudflare will be a huge blessing. Thank you for sharing your work.
PS: I haven't crossed the TypeScript divide yet so having working JavaScript examples would be helpful for stragglers like me. I looked at the https://raw.githubusercontent.com/skymethod/denoflare/v0.3.3/common/config.schema.json
and I was able to ascertain that I should use standard Worker syntax, but it took an extra couple steps to figure that out.
While I'm trying to execute my code in Denoflare, it is always complaining about my imports that have reference to the importMaps as it is recommended in Deno. Is there any config to make sure the importMaps are getting used while running denoflare?
Hi!
I'm unable to run the basic worker example.
Windows 10 Version 21H1 (OS Build 19043.1288)
➜ deno --version
deno 1.15.3 (release, x86_64-pc-windows-msvc)
v8 9.5.172.19
typescript 4.4.2
Install denoflare:
deno install --unstable --allow-read --allow-net --allow-env --name denoflare --force https://raw.githubusercontent.com/skymethod/denoflare/v0.3.0/cli/cli.ts
Clone the denoflare repository and open a command line in the examples/hello-worker
directory
Run example via: denoflare serve .\hello.ts
, this results in:
➜ denoflare serve .\hello.ts
error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'path')
const scriptPathOrUrl = scriptUrl ? scriptUrl.toString() : script!.path;
^
at serve (https://raw.githubusercontent.com/skymethod/denoflare/v0.3.0/cli/cli_serve.ts:94:72)
at async https://raw.githubusercontent.com/skymethod/denoflare/v0.3.0/cli/cli.ts:14:13
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.