Node version & code bundling

I’m just wondering what version of node is running on a forge trigger or webtrigger?
Also, to what degree there is transpilation of the source & how that works.

I’m trying to debug a scenario where my code works locally but doesn’t work the same way when I deploy or tunnel.

I’ll double-check with the team, but can you give the latest minor version of Node 12 a crack? That’s what’s hinted at in the docs.

1 Like

Yes, it seems to be 12.20.0
(I remembered I can simply log the node version with forge tunnel)

Unfortunately I’m still having my issue. I’m pretty darn sure it isn’t a forge issue but I’m so perplexed that it might actually be worth raising in case it is. No obligation to help but it may be interesting.

I’m basically just doing a super simple @slack/web-api integration.

The following code works locally (200 with message sent), but doesn’t with a forge tunnel or forge deploy.
I have gone as far as to hack interceptors into axios to log the request, and it’s identical and includes the slack token, yet slack returns not_authed for some reason.
I’m logging the first and last characters of the token to make sure the encrypted forge var is coming out OK and it looks fine.

Bizarre! I can’t imagine what could be different other than maybe something weird going on that breaks axios during the bundling step?
No idea. I noticed the example forge app that integrates with slack doesn’t use the node sdk so it made me wonder if someone ran into this?

import { WebClient, ErrorCode } from "@slack/web-api";

const slackClient = () => {
  // When using forge tunnel:
  // export FORGE_USER_VAR_MY_KEY=THE_SLACK_TOKEN_VALUE
  const SLACK_TOKEN = process.env.SLACK_TOKEN;

  if (!SLACK_TOKEN) {
    throw new Error(
      "Missing Slack Token. Ensure the Forge app is correctly configured."
    );
  } else {
    console.log(
      `We have a slack token. ${SLACK_TOKEN.substring(
        0,
        3
      )}****************${SLACK_TOKEN.substring(
        SLACK_TOKEN.length - 2,
        SLACK_TOKEN.length
      )}`
    );
  }

  return new WebClient(SLACK_TOKEN);
};

export const publishMessage = async function (channel, text) {
  console.log(`Trying to publish to ${channel}`);

  try {
    const result = await slackClient().chat.postMessage({
      text,
      channel,
    });

    console.log(result);
  } catch (error) {
    if (error.code === ErrorCode.PlatformError) {
      console.log(error.data);
    } else {
      console.log(error);
    }
  }
};