skymethod / denoflare

Develop, test, and deploy Cloudflare Workers with Deno.
https://denoflare.dev
MIT License
692 stars 33 forks source link

Error running script SyntaxError: Identifier 'concat' has already been declared at blob:null/fc6d65b1-68e1-4492-9180-8f3271ba2cd7:824:1 #57

Open supfiger opened 1 year ago

supfiger commented 1 year ago

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).

johnspurlock-skymethod commented 1 year ago

Looks like an error in your bundle output (denoflare uses deno bundle under the hood).

Try running serve without local isolation:

$ denoflare serve <path> --local-isolation none

You'll lose hot reload, but it will try to import your bundle directly in the main process, perhaps allowing you to see the error.

Could also try running deno bundle on your script and look at the output for the duplicate concat it's complaining about

supfiger commented 1 year ago

About running with --local-isolation none:

$ denoflare serve src/prod-cloudflare.ts --local-isolation none

error: Uncaught (in promise) TypeError: Relative import path "src/prod-cloudflare.ts" not prefixed with / or ./ or ../
        const module = await import(scriptPath);

$ denoflare serve ./src/prod-cloudflare.ts --local-isolation none

error: Uncaught (in promise) TypeError: Module not found "https://raw.githubusercontent.com/skymethod/denoflare/v0.5.12/common/src/prod-cloudflare.ts".
        const module = await import(scriptPath);

$ denoflare serve /Users/supfiger/coding/apps/mine/deno-grammy/src/prod-cloudflare.ts --local-isolation none

error: Uncaught (in promise) TypeError: Module not found "https://raw.githubusercontent.com/Users/supfiger/coding/apps/mine/deno-grammy/src/prod-cloudflare.ts".
        const module = await import(scriptPath);

Looks like if I provide absolute path to file, it tries to get it not from skymethod repo, but from the provided path, but it's an invalid path (and even more – my repo is private).


I also ran deno bundle src/prod-cloudflare.ts and haven’t got any error.

johnspurlock-skymethod commented 1 year ago

Do you have bare imports in your script? Denoflare supports ./ and https://... old school Deno imports, nothing that requires import map config or npm deps etc.