grammyjs/conversations

Support for Cloudflare Workers

sunyata0 opened this issue · 4 comments

Hi!

I'm running my grammy telegram bot on CFW (Cloudflare Workers) and I would like to use the @grammyjs/conversations plugin. However this plugin has an indirect dependency to @deno/shim-deno though o-son.
This dependency leads to errors at build time.

// ...
const bot = new Bot(token)
bot.use(conversations()); // This line causes the error
// ...

When I try to deploy my bot with wrangler deploy (or to run it locally with wrangler dev), I have this error:

...
✘ [ERROR] Could not resolve "fs"

    node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js:4:17:
      4 │ var fs = require('fs')
        ╵                  ~~~~

  The package "fs" wasn't found on the file system but is built into node.
  Add "node_compat = true" to your wrangler.toml file to enable Node.js compatibility.


✘ [ERROR] Could not resolve "util"

    node_modules/.pnpm/o-son@1.0.2/node_modules/o-son/script/_dnt.shims.js:7:23:
      7 │ const util_1 = require("util");
        ╵                        ~~~~~~

  The package "util" wasn't found on the file system but is built into node.
  Add "node_compat = true" to your wrangler.toml file to enable Node.js compatibility.


✘ [ERROR] Could not resolve "path"

    node_modules/.pnpm/which@2.0.2/node_modules/which/which.js:5:21:
      5 │ const path = require('path')
        ╵                      ~~~~~~

  The package "path" wasn't found on the file system but is built into node.
  Add "node_compat = true" to your wrangler.toml file to enable Node.js compatibility.


✘ [ERROR] Build failed with 108 errors:

  node_modules/.pnpm/@deno+shim-deno@0.16.1/node_modules/@deno/shim-deno/dist/deno/internal/Conn.js:17:22: ERROR: Could not resolve "net"
  node_modules/.pnpm/@deno+shim-deno@0.16.1/node_modules/@deno/shim-deno/dist/deno/internal/fs_flags.js:33:21: ERROR: Could not resolve "fs"
  node_modules/.pnpm/@deno+shim-deno@0.16.1/node_modules/@deno/shim-deno/dist/deno/internal/fs_flags.js:34:37: ERROR: Could not resolve "os"
  node_modules/.pnpm/@deno+shim-deno@0.16.1/node_modules/@deno/shim-deno/dist/deno/stable/classes/FsFile.js:28:32: ERROR: Could not resolve "fs"
  node_modules/.pnpm/@deno+shim-deno@0.16.1/node_modules/@deno/shim-deno/dist/deno/stable/classes/PermissionStatus.js:9:102: ERROR: Could not resolve "events"

I only tail 3 of the 108 errors, but they all refer to an "Could not resolve" error. The unresolved libs are the following:

  • "path"
  • "utils"
  • "util"
  • "fs"
  • "fs/promises"
  • "os"
  • "url"
  • "process"
  • "net"
  • "events"
  • "child_process"
  • "dns"
  • "tls"
  • "tty"

They are mostly in the @deno/shim-deno package (103 out of 108) but also 3 in isexe ("fs"), 1 in o-son ("util" without s) and 1 in which ("path")

Of course, I've tried to add node_compat = true in the wrangler.toml and the output is the following:

...
✘ [ERROR] Could not resolve "fs/promises"

    node_modules/.pnpm/@deno+shim-deno@0.16.1/node_modules/@deno/shim-deno/dist/deno/stable/functions/watchFs.js:5:27:
      5 │ const promises_1 = require("fs/promises");
        ╵                            ~~~~~~~~~~~~~

  The package "fs/promises" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.


✘ [ERROR] Could not resolve "fs/promises"

    node_modules/.pnpm/@deno+shim-deno@0.16.1/node_modules/@deno/shim-deno/dist/deno/stable/functions/writeFile.js:31:32:
      31 │ const fs = __importStar(require("fs/promises"));
         ╵                                 ~~~~~~~~~~~~~

  The package "fs/promises" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.


✘ [ERROR] Could not resolve "fs/promises"

    node_modules/.pnpm/@deno+shim-deno@0.16.1/node_modules/@deno/shim-deno/dist/deno/stable/functions/writeTextFile.js:31:32:
      31 │ const fs = __importStar(require("fs/promises"));
         ╵                                 ~~~~~~~~~~~~~

  The package "fs/promises" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.


✘ [ERROR] Build failed with 20 errors:

  node_modules/.pnpm/@deno+shim-deno@0.16.1/node_modules/@deno/shim-deno/dist/deno/stable/functions/chmod.js:28:32:
  ERROR: Could not resolve "fs/promises"
  node_modules/.pnpm/@deno+shim-deno@0.16.1/node_modules/@deno/shim-deno/dist/deno/stable/functions/chown.js:28:32:
  ERROR: Could not resolve "fs/promises"
  node_modules/.pnpm/@deno+shim-deno@0.16.1/node_modules/@deno/shim-deno/dist/deno/stable/functions/copyFile.js:31:32:
  ERROR: Could not resolve "fs/promises"
  node_modules/.pnpm/@deno+shim-deno@0.16.1/node_modules/@deno/shim-deno/dist/deno/stable/functions/link.js:28:32:
  ERROR: Could not resolve "fs/promises"
  node_modules/.pnpm/@deno+shim-deno@0.16.1/node_modules/@deno/shim-deno/dist/deno/stable/functions/lstat.js:31:32:
  ERROR: Could not resolve "fs/promises"

Once again I only tail 3 of the 20 errors, but as you can see, only the : "fs/promises" package leads to an error now and all the other errors are gone. And all the 20 errors are in the @deno/shim-deno package.

Of course I don't need to use "fs" for my use case, because I use the @grammyjs/storage-supabase for the storage and we don't have access to the file system in the CFW environment anyway.

My question is: will you plan to support the CFW environment for this plugin? If not, is there some workaround we can implement to bypass this issue?

Thank you for your time!

We just need to provide a web build. This is being tracked at grammyjs/grammY#372. Closing as duplicate.

Hey there
Does this have a resolution? Checked the threads and seems build needs to have web version?

Yes. As a temporary workaround, you can use tools like https://bundle.deno.dev/ and pass the raw source code URL from GitHub to it in order to obtain a web build. Or perhaps @PonomareVlad has created such a build? I'm not entirely sure.

Yes, i used @ponomarevlad/grammyjs-conversations as a temporary solution.