slackapi / deno-slack-sdk

SDK for building Run on Slack apps using Deno
https://api.slack.com/automation
MIT License
155 stars 27 forks source link

Windows Error "Could not resolve" when deploying - Local is fine #271

Closed mcsescott closed 5 months ago

mcsescott commented 7 months ago

I am getting the same error as closed issue as #258.

I am using Windows, and the local app installs and runs just fine. When I try to deploy it via slack deploy I get the following error:

Note: certain values XXXX out due to this being a public forum.

`
PS C:\Users\XXXX\Downloads\Slack Workflows\Applications\nextgen apps\new emoji alerter> slack deploy
? Choose a deployed environment XXXX-sandbox E010X9PXXXX A06GHQRXXXX

> App Manifest                
   Updated app manifest for "New Emoji Alerter" in "XXXX Org Test Env"

> App Install
   Installing "New Emoji Alerter" app to "XXXX Org Test Env"
   Updated app icon: assets/slack_new_emoji.png
   Finished in 4.8s

> Listing triggers installed to the app...

> Event trigger:

   New Emoji Added Ft06GGKHE7K3 (event)
   Created: 2024-01-29 11:14:29 -06:00 (1 hour ago)
   Collaborators:
     Scott @Scott U01H9AJXXXX
   Can be found and used by:
     everyone in all workspaces in this org granted to this app
   Hint:
     Invite your app to the channel to receive the events
   Warning:
     Slack Connect channels are unsupported

⠇ Packaging app for deploymentX [ERROR] Could not resolve "\\Users\\XXXX\\Downloads\\Slack Workflows\\Applications\\nextgen apps\\new emoji alerter\\functions\\emoji_alert_function.ts" [plugin deno-resolver]
The plugin "deno-resolver" didn't set a resolve directory, so esbuild did not search for "\\Users\\XXXX\\Downloads\\Slack Workflows\\Applications\\nextgen apps\\new emoji alerter\\functions\\emoji_alert_function.ts" on the file system.
Error bundling function file "new_emoji_alert" with esbuild
error: Uncaught (in promise) Error: Build failed with 1 error:
error: Could not resolve "\\Users\\XXXX\\Downloads\\Slack Workflows\\Applications\\nextgen apps\\new emoji alerter\\functions\\emoji_alert_function.ts"
let error = new Error(text);
              ^
at failureErrorWithLog (https://deno.land/x/esbuild@v0.19.4/mod.js:1626:15)
at https://deno.land/x/esbuild@v0.19.4/mod.js:1035:25
at runOnEndCallbacks (https://deno.land/x/esbuild@v0.19.4/mod.js:1461:45)
at buildResponseToResult (https://deno.land/x/esbuild@v0.19.4/mod.js:1033:7)
at https://deno.land/x/esbuild@v0.19.4/mod.js:1062:16
at responseCallbacks.<computed> (https://deno.land/x/esbuild@v0.19.4/mod.js:679:9)
at handleIncomingPacket (https://deno.land/x/esbuild@v0.19.4/mod.js:739:9)
at readFromStdout (https://deno.land/x/esbuild@v0.19.4/mod.js:655:7)
⠹ Packaging app for deploymentCheck C:\Users\XXXX\.slack\logs\slack-debug-20240129.log for full error logs

> error packaging project: Command for 'BuildProject' returned an error: exit status 1 (sdk_hook_invocation_failed)

Suggestion:

Run `slack doctor` to check that your system dependencies are up-to-date.

⠼ Packaging app for deployment
PS C:\Users\XXXX\Downloads\Slack Workflows\Applications\nextgen apps\new emoji alerter> slack doctor

SYSTEM

    ✔ Operating System (virtual machine orchestrator)
        Version: windows (amd64)

    ✔ Deno (a JavaScript runtime)
        Version: v1.40.2
        Recommendation: We suggest using the latest version of Deno

    ✔ Git (a version control system)
        Version: git version 2.43.0.windows.1

SLACK

    ✔ CLI (this tool for building Slack apps)
        Version: 2.15.0

    ✔ Configurations (any adjustments to settings)
        System ID: e291ea02-05f3-435c-a2ff-961fc5707a8e
        Last updated: 2024-01-29 08:45:36 -06:00
        Experiments: None

    ✔ Credentials (your Slack authentication)
        Team domain: XXXX-collab-and-msg
        Team ID: T0115PPXXXX
        User ID: U01H9AJXXXX
        Last updated: 2024-01-29 08:45:30 -06:00
        Authorization level: Workspace
        Token status: Valid

        Team domain: XXXX-sandbox
        Team ID: T013956XXXX
        User ID: U01H9AJXXXX
        Last updated: 2024-01-29 08:45:30 -06:00
        Authorization level: Workspace
        Token status: Valid

        Team domain: XXXX-sandbox
        Team ID: E010X9PXXXX
        User ID: U01H9AJXXXX
        Last updated: 2024-01-29 09:26:40 -06:00
        Authorization level: Organization
        Token status: Valid

PROJECT

    ✔ Configurations (your project's CLI settings)
        Project ID: d0699538-7250-4939-8916-a36a6e3eeb16

    ✔ Dependencies (requisites for development)
        deno_slack_hooks: 1.2.3
        deno_slack_sdk: 2.5.0
        deno_slack_api: 2.1.2

Errors: 0

> We would love to know how things are going
   Survey your development experience with slack.exe feedback --name platform-improvements

PS C:\Users\XXXX\Downloads\Slack Workflows\Applications\nextgen apps\new emoji alerter> 
`

I see no errors in my code, so not sure if the resolution mentioned above would apply. If there was an error, then why would it work when running locally?

WilliamBergamin commented 6 months ago

Hi @mcsescott is this this behavior still happening?

mcsescott commented 6 months ago

Thanks for the follow-up. Yes, it is. I just tried a different app and the issue still occurs. It installs fine with slack run but fails with slack deploy

⠴ Packaging app for deploymentX [ERROR] Could not resolve "\\Users\\spatton\\Downloads\\Slack Workflows\\Applications\\NextGen Apps\\MPDM to Channel\\functions\\mpdm_to_private_function.ts" [plugin deno-resolver]
The plugin "deno-resolver" didn't set a resolve directory, so esbuild did not search for "\\Users\\spatton\\Downloads\\Slack Workflows\\Applications\\NextGen Apps\\MPDM to Channel\\functions\\mpdm_to_private_function.ts" on the file system.
Error bundling function file "mpdm2private_function" with esbuild
error: Uncaught (in promise) Error: Build failed with 1 error:
error: Could not resolve "\\Users\\spatton\\Downloads\\Slack Workflows\\Applications\\NextGen Apps\\MPDM to Channel\\functions\\mpdm_to_private_function.ts"
let error = new Error(text);
              ^
at failureErrorWithLog (https://deno.land/x/esbuild@v0.19.4/mod.js:1626:15)
at https://deno.land/x/esbuild@v0.19.4/mod.js:1035:25
at runOnEndCallbacks (https://deno.land/x/esbuild@v0.19.4/mod.js:1461:45)
at buildResponseToResult (https://deno.land/x/esbuild@v0.19.4/mod.js:1033:7)
at https://deno.land/x/esbuild@v0.19.4/mod.js:1062:16
at responseCallbacks.<computed> (https://deno.land/x/esbuild@v0.19.4/mod.js:679:9)
at handleIncomingPacket (https://deno.land/x/esbuild@v0.19.4/mod.js:739:9)
at readFromStdout (https://deno.land/x/esbuild@v0.19.4/mod.js:655:7)
at https://deno.land/x/esbuild@v0.19.4/mod.js:1924:11
at eventLoopTick (ext:core/01_core.js:65:7)
⠹ Packaging app for deploymentCheck C:\Users\spatton\.slack\logs\slack-debug-20240221.log for full error logs
WilliamBergamin commented 6 months ago

This seems to be related to how the functions are being bundled before they are sent to the Slack, here is the relevant snippet

Important to note that before bundling with esbuild we try to bundle with the the default deno bundler this seems to fail as well

This may be due to the path of your project their seems to be some folders that contain spaces, I've been bit by this in the past could you try renaming your folders something like \Downloads\Slack_Workflows\Applications\NextGen_Apps\MPDM_to_Channel\functions\mpdm_to_private_function.ts

Also if it is possible could you share the contents of mpdm_to_private_function.ts?

mcsescott commented 6 months ago

I am also working with a couple of TAs (who might reach out to you internally), and today we tried a couple of things:

  1. The sample Hello World app was able to be deployed with spaces in the directory names.
  2. I moved one of the apps to a completely different directory with no spaces, and got the same error, that it could not resolve. There must be something about the functions that is causing it to error.

As far as sharing the functions, I would rather not do that on a public forum. I will see if I can pare it down to just the bare bones function definition with simple code to see if it will work.

mcsescott commented 6 months ago

Update: I updated the Slack CLI (as well as the deno hooks and api via slack update) and the error message is a little different:

⠴ Packaging app for deploymenterror: Uncaught (in promise) Error: Could not find file: C:\Users\spatton\Downloads\Slack\functions\mpdm_to_private_function.ts. Make sure the function 
definition with ID mpdm2private_function's source_file is relative to your project root.
throw new Error(
              ^
at validateManifestFunctions (https://deno.land/x/deno_slack_hooks@1.2.3/utilities.ts:68:15)
at eventLoopTick (ext:core/01_core.js:65:7)
at async validateAndCreateFunctions (https://deno.land/x/deno_slack_hooks@1.2.3/build.ts:25:3)
at async https://deno.land/x/deno_slack_hooks@1.2.3/build.ts:144:3
Packaging app for deployment
Check C:\Users\spatton\.slack\logs\slack-debug-20240223.log for full error logs

> error packaging project: Command for 'BuildProject' returned an error: exit status 1 (sdk_hook_invocation_failed)

Suggestion:

Run `slack doctor` to check that your system dependencies are up-to-date.

PS C:\Users\spatton\Downloads\Slack Workflows\Applications\nextgen apps\mpdm to channel> slack doctor

SYSTEM

    ✔ Operating System (program scheduler and such)
        Version: windows (amd64)

    ✔ Deno (a JavaScript runtime)
        Version: v1.40.4
        Recommendation: We suggest using the latest version of Deno

    ✔ Git (a version control system)
        Version: git version 2.43.0.windows.1

SLACK

    ✔ CLI (this tool for building Slack apps)
        Version: 2.18.0

    ✔ Configurations (any adjustments to settings)
        System ID: e291ea02-05f3-435c-a2ff-961fc5707a8e
        Last updated: 2024-02-23 10:59:00 -06:00
        Experiments: None

    ✔ Credentials (your Slack authentication)
        Team domain: verizon-sandbox
        Team ID: E010X9P37H6
        User ID: U01H9AJPCUF
        Last updated: 2024-02-23 09:23:55 -06:00
        Authorization level: Organization
        Token status: Valid

PROJECT

    ✔ Configurations (your project's CLI settings)
        Project ID: 1c28dc06-3a3e-40cc-aa32-ce0d3e004ca6

    ✔ Dependencies (requisites for development)
        deno_slack_hooks: 1.2.3
        deno_slack_sdk: 2.6.0
        deno_slack_api: 2.2.0

Errors: 0
WilliamBergamin commented 6 months ago

Just to do be rigorous does this file path C:\Users\<your_user>\Downloads\Slack\functions\mpdm_to_private_function.ts exist on your machine?

And is the value of the source_file field in the function definition relative to the root of your project? Example

export const PostIssueMessage = DefineFunction({
  callback_id: "post_issue_message",
  title: "Post an issue to channel",
  description: "Create an issue message from submitted form",
  source_file: "functions/post_issue_message.ts", // not C:\Users\<your_user>\path\to\project\functions\post_issue_message.ts
  input_parameters: {
    properties: {
      channel: {
        type: Schema.slack.types.channel_id,
      }
    },
    required: ["channel"],
  },
  output_parameters: {
    properties: {
      channel: {
        type: Schema.slack.types.channel_id,
      },
    },
    required: [],
  },
});
mcsescott commented 6 months ago

Yes, and yes (and yes). Again, the app will run if it run locally slack run it is just when I try to deploy it is when I get the errors.

I have tried directories with spaces and without. I even get the error on the simple Hello World app tutorial (without any modifications to the code).

WilliamBergamin commented 6 months ago

Could you try running the following steps and sharing the results, these work on my end

  1. slack create test-hello-world -t https://github.com/slack-samples/deno-hello-world
  2. cd test-hello-world/
  3. slack deploy + create the trigger
mcsescott commented 5 months ago

Working with my TA, we have discovered the issue, and it appears to be a Deno linting issue with VSCode. It basically comes down to Deno being very type strict, unlike Javascript.

We adjusted the code (and added checks/assertions for null values), and I have been able to deploy it now. Thanks for your assistance.

ericmutta commented 3 weeks ago

It basically comes down to Deno being very type strict, unlike Javascript.

I was facing the same problem/error as @mcsescott and the sentence above gave me the idea to comment out some code that calls the GitHub API in a custom function...I was then able to deploy just fine :+1:

@WilliamBergamin the error message being returned by the Slack CLI in this case is quite perplexing. It seems that the underlying cause is "linting" failures. For example, in my case my function file has this import:

import { Octokit } from "https://esm.sh/octokit@4.0.2?dts";

In VS Code, deno-lint will show me this error (note the deno-lint(no-unused-vars) text):

image

The linter is telling me I haven't used the Octokit reference that I imported. When this is the case slack deploy will fail with the error messages @mcsescott was posting.

👉 If I comment out the unused import then the linting error disappears and slack deploy works just fine 👈

I don't know the underlying mechanics, but if slack deploy is able to report errors directly from the underlying build tool, it may help make scenarios like this easier to troubleshoot on the CLI 👍