slackapi / bolt-js

A framework to build Slack apps using JavaScript
https://slack.dev/bolt-js
MIT License
2.74k stars 394 forks source link

deno support #1763

Closed scarf005 closed 1 year ago

scarf005 commented 1 year ago

hello, today i tried using bolt-js in deno, however it does not seem to work.

import { App } from "npm:@slack/bolt"
import { config } from "https://deno.land/x/dotenv@v3.2.2/mod.ts"

type DotEnv = Record<
  "SLACK_BOT_TOKEN" | "SLACK_SIGNING_SECRET" | "SLACK_APP_TOKEN" | "PORT",
  string
>

const { SLACK_BOT_TOKEN, SLACK_SIGNING_SECRET, SLACK_APP_TOKEN, PORT } = config(
  {
    safe: true,
  },
) as DotEnv
const port = parseInt(PORT, 10)

const app = new App({
  token: SLACK_BOT_TOKEN,
  signingSecret: SLACK_SIGNING_SECRET,
  appToken: SLACK_APP_TOKEN,
  socketMode: true,
  port,
})

const main = async () => {
  // Start your app
  await app.start()

  console.log(`⚡️ Bolt app running at ${port}`)
}

await main()
error: Uncaught SyntaxError: The requested module 'npm:@slack/bolt' does not provide an export named 'App'
import { App } from 'npm:@slack/bolt'
         ^
    at <anonymous> (file:///home/scarf/repo/etc/bolt-hello-world/main.ts:1:10)

when i change the import to import * as bolt from "npm:@slack/bolt", i get this instead:

error: Uncaught SyntaxError: The requested module 'npm:@slack/bolt' does not provide an export named 'App'
import { App } from 'npm:@slack/bolt'
         ^
    at <anonymous> (file:///home/scarf/repo/etc/bolt-hello-world/main.ts:1:10)
 !  ◰³ .venv  ~/r/e/bolt-hello-world  deno run -A main.ts
error: Uncaught TypeError: The "path" argument must be of type string. Received undefined
    at assertPath (ext:deno_node/path/_util.ts:8:15)
    at basename (ext:deno_node/path/posix.ts:202:5)
    at Object.<anonymous> (file:///home/scarf/.cache/deno/npm/registry.npmjs.org/@slack/web-api/6.8.1/dist/instrument.js:44:28)
    at Object.<anonymous> (file:///home/scarf/.cache/deno/npm/registry.npmjs.org/@slack/web-api/6.8.1/dist/instrument.js:66:4)
    at Module._compile (ext:deno_node_loading/02_require.js:745:34)
    at Object.Module._extensions..js (ext:deno_node_loading/02_require.js:778:10)
    at Module.load (ext:deno_node_loading/02_require.js:656:32)
    at Function.Module._load (ext:deno_node_loading/02_require.js:513:12)
    at Module.require (ext:deno_node_loading/02_require.js:678:19)
    at require (ext:deno_node_loading/02_require.js:818:16)

could it be possible for bolt-js to support deno? thank you for your time.

mwbrooks commented 1 year ago

Hey @scarf005 👋🏻 Super cool to see that you're experimenting with Deno and Bolt JS 🎉

⚠️ This is new territory and we haven't started to test Bolt JS compatibility with Deno. In the earlier days, before official Deno/npm compatibility, we had issues with some of our dependencies such as axios.

Similar to you, I had trouble getting the dereferencing syntax to work: import { App } from "npm:@slack/bolt"

My workaround was to import the entire module and reference the App object. It's not ideal, but it's a step forward:

import bolt from "npm:@slack/bolt"

// ...

const app = new bolt.App({

Unfortunately, I'm now seeing a new error and I'm unsure where it's coming from. Do you experience the same error?

$ deno run --allow-read --allow-env main.ts

error: Uncaught TypeError: The "path" argument must be of type string. Received undefined
    at assertPath (ext:deno_node/path/_util.ts:8:15)
    at basename (ext:deno_node/path/posix.ts:202:5)
    at Object.<anonymous> (file:///Users/michael.brooks/Library/Caches/deno/npm/registry.npmjs.org/@slack/web-api/6.8.1/dist/instrument.js:44:28)
    at Object.<anonymous> (file:///Users/michael.brooks/Library/Caches/deno/npm/registry.npmjs.org/@slack/web-api/6.8.1/dist/instrument.js:66:4)
    at Module._compile (ext:deno_node_loading/02_require.js:745:34)
    at Object.Module._extensions..js (ext:deno_node_loading/02_require.js:778:10)
    at Module.load (ext:deno_node_loading/02_require.js:656:32)
    at Function.Module._load (ext:deno_node_loading/02_require.js:513:12)
    at Module.require (ext:deno_node_loading/02_require.js:678:19)
    at require (ext:deno_node_loading/02_require.js:818:16)
filmaj commented 1 year ago

I recall experimenting in this area a while ago, and I left some TODOs related to this in the web-api code.

If I understand correctly, @mwbrooks' stack trace points to the basename invocation here, and the argument being provided to it (process.title) is not an API deno implements - thus, undefined.

I did prior work in this area, but couldn't get all the way to full compatibility - at least in the dependent web-api module (which is revisioned on github.com/slackapi/node-slack-sdk/packages/web-api and bolt relies on). There is a dedicated npm run build:deno run script that tries to build a deno-compatible version of web-api and fill in some of these gaps - like assigning values to process.title and injecting some of the deno shims I put together. We even had a GitHub Action that would run through this build and deploy the web-api client out to deno.land under slack_web_api - but we removed it a while back as a) it didn't have full feature support due to some missing system APIs from deno (like proxying support) and b) we didn't know whether there would be much interest in it.

hardeep commented 1 year ago

@filmaj I just ran into this trying to consume @slack/web-api using the npm specifier in deno.

error: Uncaught TypeError: The "path" argument must be of type string. Received undefined
    at assertPath (ext:deno_node/path/_util.ts:8:15)
    at basename (ext:deno_node/path/posix.ts:202:5)
    at Object.<anonymous> (file:///Users/hardeep/Library/Caches/deno/npm/registry.npmjs.org/@slack/web-api/6.8.1/dist/instrument.js:46:28)
    at Object.<anonymous> (file:///Users/hardeep/Library/Caches/deno/npm/registry.npmjs.org/@slack/web-api/6.8.1/dist/instrument.js:69:4)
    at Module._compile (ext:deno_node_loading/02_require.js:745:34)
    at Object.Module._extensions..js (ext:deno_node_loading/02_require.js:778:10)
    at Module.load (ext:deno_node_loading/02_require.js:656:32)
    at Function.Module._load (ext:deno_node_loading/02_require.js:513:12)
    at Module.require (ext:deno_node_loading/02_require.js:678:19)
    at require (ext:deno_node_loading/02_require.js:818:16)

Is the best path forward to use the build script?

filmaj commented 1 year ago

Ohai @hardeep 😄 I believe that is the case, yes. the npm: specifier in deno should try to put in place a lot of these node compatibility shims that deno is working on automatically but depending on the API, the compatibility shim might not be available. You may have to fudge around with the build script a bit as the manual shims I put into place may be no longer needed or need tweaking, but the general gist of the approach should continue to work.

filmaj commented 1 year ago

Another option is to give the deno-slack-api repo a shot. It is an API client built for deno, BUT, it has a very minimal feature set compared to @slack/web-api: no automatic retry, no proxy support, and many other things.

github-actions[bot] commented 1 year ago

👋 It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.

github-actions[bot] commented 1 year ago

As this issue has been inactive for more than one month, we will be closing it. Thank you to all the participants! If you would like to raise a related issue, please create a new issue which includes your specific details and references this issue number.

myftija commented 1 year ago

Hi @filmaj, thanks for the insights. Following up on the discussion, are there any future plans to add deno support to bolt?

filmaj commented 1 year ago

@myftija not at this time, though Deno has ever-improving compatibility with npm packages / node ecosystem, so at some point bolt should "just work" for deno.

hotpinkturban commented 1 month ago

Hey @scarf005 👋🏻 Super cool to see that you're experimenting with Deno and Bolt JS 🎉

⚠️ This is new territory and we haven't started to test Bolt JS compatibility with Deno. In the earlier days, before official Deno/npm compatibility, we had issues with some of our dependencies such as axios.

Similar to you, I had trouble getting the dereferencing syntax to work: import { App } from "npm:@slack/bolt"

My workaround was to import the entire module and reference the App object. It's not ideal, but it's a step forward:

import bolt from "npm:@slack/bolt"

// ...

const app = new bolt.App({

Unfortunately, I'm now seeing a new error and I'm unsure where it's coming from. Do you experience the same error?

$ deno run --allow-read --allow-env main.ts

error: Uncaught TypeError: The "path" argument must be of type string. Received undefined
    at assertPath (ext:deno_node/path/_util.ts:8:15)
    at basename (ext:deno_node/path/posix.ts:202:5)
    at Object.<anonymous> (file:///Users/michael.brooks/Library/Caches/deno/npm/registry.npmjs.org/@slack/web-api/6.8.1/dist/instrument.js:44:28)
    at Object.<anonymous> (file:///Users/michael.brooks/Library/Caches/deno/npm/registry.npmjs.org/@slack/web-api/6.8.1/dist/instrument.js:66:4)
    at Module._compile (ext:deno_node_loading/02_require.js:745:34)
    at Object.Module._extensions..js (ext:deno_node_loading/02_require.js:778:10)
    at Module.load (ext:deno_node_loading/02_require.js:656:32)
    at Function.Module._load (ext:deno_node_loading/02_require.js:513:12)
    at Module.require (ext:deno_node_loading/02_require.js:678:19)
    at require (ext:deno_node_loading/02_require.js:818:16)

I am getting this error importing this package in Stackblitz. Any ideas on this??