Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Cloudflare Workers #91

Closed
sunyata0 opened this issue Nov 1, 2023 · 4 comments
Closed

Support for Cloudflare Workers #91

sunyata0 opened this issue Nov 1, 2023 · 4 comments
Labels
duplicate This issue or pull request already exists

Comments

@sunyata0
Copy link

sunyata0 commented Nov 1, 2023

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/[email protected]/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/[email protected]/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/[email protected]/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/@[email protected]/node_modules/@deno/shim-deno/dist/deno/internal/Conn.js:17:22: ERROR: Could not resolve "net"
  node_modules/.pnpm/@[email protected]/node_modules/@deno/shim-deno/dist/deno/internal/fs_flags.js:33:21: ERROR: Could not resolve "fs"
  node_modules/.pnpm/@[email protected]/node_modules/@deno/shim-deno/dist/deno/internal/fs_flags.js:34:37: ERROR: Could not resolve "os"
  node_modules/.pnpm/@[email protected]/node_modules/@deno/shim-deno/dist/deno/stable/classes/FsFile.js:28:32: ERROR: Could not resolve "fs"
  node_modules/.pnpm/@[email protected]/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/@[email protected]/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/@[email protected]/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/@[email protected]/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/@[email protected]/node_modules/@deno/shim-deno/dist/deno/stable/functions/chmod.js:28:32:
  ERROR: Could not resolve "fs/promises"
  node_modules/.pnpm/@[email protected]/node_modules/@deno/shim-deno/dist/deno/stable/functions/chown.js:28:32:
  ERROR: Could not resolve "fs/promises"
  node_modules/.pnpm/@[email protected]/node_modules/@deno/shim-deno/dist/deno/stable/functions/copyFile.js:31:32:
  ERROR: Could not resolve "fs/promises"
  node_modules/.pnpm/@[email protected]/node_modules/@deno/shim-deno/dist/deno/stable/functions/link.js:28:32:
  ERROR: Could not resolve "fs/promises"
  node_modules/.pnpm/@[email protected]/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!

@KnorpelSenf
Copy link
Member

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

@KnorpelSenf KnorpelSenf added the duplicate This issue or pull request already exists label Nov 1, 2023
@TrilipuT
Copy link

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

@KnorpelSenf
Copy link
Member

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.

@TrilipuT
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants