Can't get my simple ForgeUI app running in Jira Cloud... deploy fails

Hi!

I’m working on my application and deployment suddenly stared to fail with the following message:

Error: Error thrown in the snapshot context.
App code snapshot error: Snapshot error occurred: Error: ForgeUI is not defined
Learn more about the snapshot context at http://go.atlassian.com/forge-snapshot-context.

If I disable snapshoting, then the app will fail runtime:

There was an error invoking the function - invalid manifest

Error: invalid manifest
    at new h (/opt/index.js:16:150244)
    at Function.fromFile (/opt/index.js:16:150412)
    at Function.initialize (/opt/index.js:22:99573)
    at Object.e.initializeSandbox (/opt/index.js:16:8135)
    at /opt/index.js:22:61536
    at Object.<anonymous> (/opt/index.js:22:61721)
    at n (/opt/index.js:1:110)
    at /opt/index.js:1:902
    at Object.<anonymous> (/opt/index.js:1:913)
    at Module._compile (internal/modules/cjs/loader.js:956:30)

In case of tunneling, the message is different (if snapshots are turned off):

There was an error invoking the function - ForgeUI is not defined

ReferenceError: ForgeUI is not defined
    at Module.<anonymous> (index.js:12841:70)
    at __webpack_require__ (index.js:20:30)
    at index.js:84:18
    at index.js:87:10
    at (<isolated-vm boundary>)
    at compileAndRun (/tunnel/node_modules/@forge/runtime/out/sandbox-isolate/index.js:71:22)

I found the following topic:

I tried everything written there (downgrade to node LTS, disable snapshots), but nothing helped.
That problem caused by internal error at the Cloud and resolved. It was back in June…

I’m not using googleapis, just @forge/ui and @forge/api
The app is now quite similar to simple example apps.

The annoying is that it worked until now. I don’t know how to continue work …

1 Like

In your code - how are you importing @forge/ui ? Also (and excuse the silly question) - did you npm install @forge/ui ?

When you do the deploy, you can add --verbose to it - it gets quite chatty but I’ve found the verbose content identifies things.

3 Likes

I started getting the same error today, and I found a few other posts about “invalid manifest”. Forge bug?

Hey @GT1, thanks for raising this. I’m investigating this now and will get back to you when I’ve found the issue, or may ask for more info if I am not able to.

Hey @GT1, we just deployed what we believe should be a fix for the issue. Could you please re-deploy and try again?

Hi!

Thanks for the reply. The deployment still not working. Here is the chatty output with --verbose option. In this case, I turned snapshots back (because it will fail deploy process, overwise it fails on runtime):

$ forge deploy
Deploying your app to the development environment.
Press Ctrl+C to cancel.

Running forge lint...
No issues found.

✕ Deploying your app to development...

ℹ Packaging app files
ℹ Uploading app
ℹ Validating manifest
ℹ Snapshotting functions

Error: Error thrown in the snapshot context.
App code snapshot error: Snapshot error occurred: Error: ForgeUI is not defined
Learn more about the snapshot context at http://go.atlassian.com/forge-snapshot-context.

Rerunning the command with --verbose may give more details.


$ forge deploy --verbose
Deploying your app to the development environment.
Press Ctrl+C to cancel.

Running forge lint...
No issues found.

▶️  GraphQL https://api.atlassian.com/graphql
Query: 
          query forge_cli_getMigrationKeys($id: ID!, $key: String!) {
            app(id: $id) {
              environmentByKey(key: $key) {
                id
                versions(first: 1) {
                  edges {
                    node {
                      isLatest
                      migrationKeys {
                        jira
                        confluence
                      }
                    }
                  }
                }
              }
              marketplaceApp {
                appKey
              }
            }
          }
     
Variables: {
  "id": "ari:cloud:ecosystem::app/47445c04-1d74-4dfa-a043-2120d4cd664b",
  "key": "default"
}
◀️  GraphQL
Request ID: 718160830daf01c2
Result: {
  "app": {
    "environmentByKey": {
      "id": "fe0e645c-ea70-4d7d-a52d-1d2494a662bd",
      "versions": {
        "edges": [
          {
            "node": {
              "isLatest": true,
              "migrationKeys": null
            }
          }
        ]
      }
    },
    "marketplaceApp": null
  }
}
▶️  GraphQL https://api.atlassian.com/graphql
Query: 
      query forge_cli_getApplicationInstallations($id: ID!) {
        app(id: $id) {
          environments {
            key
            installations {
              id
              installationContext,
              version {
                isLatest
              }
            }
          }
        }
      }
    
Variables: {
  "id": "ari:cloud:ecosystem::app/47445c04-1d74-4dfa-a043-2120d4cd664b"
}
◀️  GraphQL
Request ID: 38b3a0174454a8d5
Result: {
  "app": {
    "environments": [
      {
        "key": "production",
        "installations": []
      },
      {
        "key": "staging",
        "installations": []
      },
      {
        "key": "default",
        "installations": [
          {
            "id": "58c59cd0-ce18-4c50-8e43-a748888531d9",
            "installationContext": "ari:cloud:jira::site/31732856-23b0-4bf7-94ac-b82be2c30c33",
            "version": {
              "isLatest": true
            }
          },
          {
            "id": "22bbfe78-ec0c-4143-9289-175d4c3abfcc",
            "installationContext": "ari:cloud:identity::site/31732856-23b0-4bf7-94ac-b82be2c30c33",
            "version": {
              "isLatest": true
            }
          }
        ]
      }
    ]
  }
}
▶️  GraphQL https://api.atlassian.com/graphql
Query: 
      query forge_cli_getHostnameForTenantContexts($cloudIds: [ID!]!) {
        tenantContexts(cloudIds: $cloudIds) {
          hostName
        }
      }
    
Variables: {
  "cloudIds": [
    "31732856-23b0-4bf7-94ac-b82be2c30c33"
  ]
}
◀️  GraphQL
Request ID: 74f75892c149af76
Result: {
  "tenantContexts": [
    {
      "hostName": "gt-dev.atlassian.net"
    }
  ]
}
Deploying your app to development...

ℹ Packaging app files
  Packaging bundled files
  Packaging the manifest.yml file from /home/gt/www/worklog/manifest.yml
  File added to archive: index.js
  File added to archive: index.js.map
  File added to archive: manifest.yml
  Archive created: /tmp/tmp-11705xkJBIleOkDMB.zip
ℹ Uploading app
  ▶️  GraphQL https://api.atlassian.com/graphql
Query: 
      mutation forge_cli_getDeploymentUrl($input: CreateAppDeploymentUrlInput!) {
        createAppDeploymentUrl(input: $input) {
          success
          errors {
            message
            extensions {
              errorType
            }
          }
          deploymentUrl
        }
      }
    
Variables: {
  "input": {
    "appId": "ari:cloud:ecosystem::app/47445c04-1d74-4dfa-a043-2120d4cd664b"
  }
}
  ◀️  GraphQL
Request ID: 9849abb8fb65e7b0
Result: {
  "createAppDeploymentUrl": {
    "success": true,
    "errors": null,
    "deploymentUrl": "https://deployment-artifacts-372253104996-us-west-2.s3.us-west-2.amazonaws.com/47445c04-1d74-4dfa-a043-2120d4cd664b_16d8ed85-cda5-487e-a009-8eb356727c5a?Content-Type=application%2Fzip&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIAVNLADTNSJVFA37CX%2F20210825%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20210825T091027Z&X-Amz-Expires=300&X-Amz-Security-Token=FwoGZXIvYXdzEBoaDJUfh%2FOFgwZrw7yJgSLIASM%2BtH3xoh94%2BcITF1SDMtFr722HxS%2BADGf%2BWscGCyiHNdUkbuSIOO6OxB44xBSPYqrLdY4OLEut6Sph%2FbmMErzLq8taloGadZlrpY6T8cbSSrECNEoEws8nslZwSP1H7iZm4%2FhzZQ835xxlxFB5fVuq5%2FyJNfCUZaWum7iT3VjyAEDzxSvPBY1y8Wc%2F5MxSa9IjG%2FY3hLtmynsIYDPD%2BUGq6rDOv44gNchaGIwFJu%2BS8rYTv8euVGX%2BcU07mux6ftgxtlY88jJZKPCDmIkGMi1h4kZXnpNwomjByF6ASVxsSo5uPW86DtmCePUH3UeSBPzqqofTQ0EFLlVUwJ8%3D&X-Amz-Signature=cd3c21145c7f2ef775b2ac7e9fb051748f25744bb834888f1db3b0a8461bfd65&X-Amz-SignedHeaders=host"
  }
}
  Uploading archive to https://deployment-artifacts-372253104996-us-west-2.s3.us-west-2.amazonaws.com/47445c04-1d74-4dfa-a043-2120d4cd664b_16d8ed85-cda5-487e-a009-8eb356727c5a?Content-Type=application%2Fzip&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIAVNLADTNSJVFA37CX%2F20210825%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20210825T091027Z&X-Amz-Expires=300&X-Amz-Security-Token=FwoGZXIvYXdzEBoaDJUfh%2FOFgwZrw7yJgSLIASM%2BtH3xoh94%2BcITF1SDMtFr722HxS%2BADGf%2BWscGCyiHNdUkbuSIOO6OxB44xBSPYqrLdY4OLEut6Sph%2FbmMErzLq8taloGadZlrpY6T8cbSSrECNEoEws8nslZwSP1H7iZm4%2FhzZQ835xxlxFB5fVuq5%2FyJNfCUZaWum7iT3VjyAEDzxSvPBY1y8Wc%2F5MxSa9IjG%2FY3hLtmynsIYDPD%2BUGq6rDOv44gNchaGIwFJu%2BS8rYTv8euVGX%2BcU07mux6ftgxtlY88jJZKPCDmIkGMi1h4kZXnpNwomjByF6ASVxsSo5uPW86DtmCePUH3UeSBPzqqofTQ0EFLlVUwJ8%3D&X-Amz-Signature=cd3c21145c7f2ef775b2ac7e9fb051748f25744bb834888f1db3b0a8461bfd65&X-Amz-SignedHeaders=host...
  ▶️  GraphQL https://api.atlassian.com/graphql
Query: 
      mutation forge_cli_deployApplication($input: CreateAppDeploymentInput!) {
        createAppDeployment(input: $input) {
          success
          errors {
            message
            extensions {
              errorType
            }
          }
          deployment {
            id
          }
        }
      }
    
Variables: {
  "input": {
    "appId": "ari:cloud:ecosystem::app/47445c04-1d74-4dfa-a043-2120d4cd664b",
    "environmentKey": "default",
    "artifactUrl": "https://deployment-artifacts-372253104996-us-west-2.s3.us-west-2.amazonaws.com/47445c04-1d74-4dfa-a043-2120d4cd664b_16d8ed85-cda5-487e-a009-8eb356727c5a?Content-Type=application%2Fzip&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIAVNLADTNSJVFA37CX%2F20210825%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20210825T091027Z&X-Amz-Expires=300&X-Amz-Security-Token=FwoGZXIvYXdzEBoaDJUfh%2FOFgwZrw7yJgSLIASM%2BtH3xoh94%2BcITF1SDMtFr722HxS%2BADGf%2BWscGCyiHNdUkbuSIOO6OxB44xBSPYqrLdY4OLEut6Sph%2FbmMErzLq8taloGadZlrpY6T8cbSSrECNEoEws8nslZwSP1H7iZm4%2FhzZQ835xxlxFB5fVuq5%2FyJNfCUZaWum7iT3VjyAEDzxSvPBY1y8Wc%2F5MxSa9IjG%2FY3hLtmynsIYDPD%2BUGq6rDOv44gNchaGIwFJu%2BS8rYTv8euVGX%2BcU07mux6ftgxtlY88jJZKPCDmIkGMi1h4kZXnpNwomjByF6ASVxsSo5uPW86DtmCePUH3UeSBPzqqofTQ0EFLlVUwJ8%3D&X-Amz-Signature=cd3c21145c7f2ef775b2ac7e9fb051748f25744bb834888f1db3b0a8461bfd65&X-Amz-SignedHeaders=host"
  }
}
  ◀️  GraphQL
Request ID: b6e43c7546e86888
Result: {
  "createAppDeployment": {
    "success": true,
    "errors": null,
    "deployment": {
      "id": "21"
    }
  }
}
  ▶️  GraphQL https://api.atlassian.com/graphql
Query: 
        query forge_cli_getApplicationDeploymentStatus($appId: ID!, $environmentKey: String!, $id: ID!) {
          appDeployment(appId: $appId, environmentKey: $environmentKey, id: $id) {
            status
            errorDetails {
              code
              message
              fields
            }
            stages {
              description
              events {
                __typename
                stepName
                createdAt
                ...on AppDeploymentLogEvent {
                  message
                  level
                }
                ...on AppDeploymentSnapshotLogEvent {
                  message
                  level
                }
                ... on AppDeploymentTransitionEvent {
                  newStatus
                }
              }
            }
          }
        }
      
Variables: {
  "appId": "ari:cloud:ecosystem::app/47445c04-1d74-4dfa-a043-2120d4cd664b",
  "environmentKey": "default",
  "id": "21"
}
  ◀️  GraphQL
Request ID: d2a40cd0b52ab7ef
Result: {
  "appDeployment": {
    "status": "FAILED",
    "errorDetails": {
      "code": "APP_CODE_SNAPSHOT_FAILED",
      "message": "Snapshot error occurred: Error: ForgeUI is not defined",
      "fields": {
        "stack": [
          "Error: Snapshot error occurred: Error: ForgeUI is not defined",
          "    at /var/task/index.js:65634:27"
        ]
      }
    },
    "stages": [
      {
        "description": "Validating manifest",
        "events": [
          {
            "__typename": "AppDeploymentTransitionEvent",
            "stepName": "Init deployment",
            "createdAt": "2021-08-25T09:10:30.067Z",
            "newStatus": "STARTED"
          },
          {
            "__typename": "AppDeploymentTransitionEvent",
            "stepName": "Init deployment",
            "createdAt": "2021-08-25T09:10:30.171Z",
            "newStatus": "DONE"
          },
          {
            "__typename": "AppDeploymentTransitionEvent",
            "stepName": "Download manifest",
            "createdAt": "2021-08-25T09:10:30.174Z",
            "newStatus": "STARTED"
          },
          {
            "__typename": "AppDeploymentLogEvent",
            "stepName": "Download manifest",
            "createdAt": "2021-08-25T09:10:30.175Z",
            "message": "Upload URL is valid",
            "level": "INFO"
          },
          {
            "__typename": "AppDeploymentLogEvent",
            "stepName": "Download manifest",
            "createdAt": "2021-08-25T09:10:30.367Z",
            "message": "Found manifest file",
            "level": "INFO"
          },
          {
            "__typename": "AppDeploymentLogEvent",
            "stepName": "Download manifest",
            "createdAt": "2021-08-25T09:10:30.369Z",
            "message": "Manifest is a valid YAML",
            "level": "INFO"
          },
          {
            "__typename": "AppDeploymentTransitionEvent",
            "stepName": "Download manifest",
            "createdAt": "2021-08-25T09:10:30.371Z",
            "newStatus": "DONE"
          },
          {
            "__typename": "AppDeploymentTransitionEvent",
            "stepName": "Validate manifest",
            "createdAt": "2021-08-25T09:10:30.372Z",
            "newStatus": "STARTED"
          },
          {
            "__typename": "AppDeploymentLogEvent",
            "stepName": "Validate manifest",
            "createdAt": "2021-08-25T09:10:30.487Z",
            "message": "Manifest passed common validations",
            "level": "INFO"
          },
          {
            "__typename": "AppDeploymentLogEvent",
            "stepName": "Validate manifest",
            "createdAt": "2021-08-25T09:10:30.488Z",
            "message": "Manifest doesn't have forbidden modules",
            "level": "INFO"
          },
          {
            "__typename": "AppDeploymentLogEvent",
            "stepName": "Validate manifest",
            "createdAt": "2021-08-25T09:10:30.491Z",
            "message": "Manifest passed function names validations",
            "level": "INFO"
          },
          {
            "__typename": "AppDeploymentLogEvent",
            "stepName": "Validate manifest",
            "createdAt": "2021-08-25T09:10:30.492Z",
            "message": "Manifest passed cleanup function validation",
            "level": "INFO"
          },
          {
            "__typename": "AppDeploymentTransitionEvent",
            "stepName": "Validate manifest",
            "createdAt": "2021-08-25T09:10:30.493Z",
            "newStatus": "DONE"
          }
        ]
      },
      {
        "description": "Snapshotting functions",
        "events": [
          {
            "__typename": "AppDeploymentTransitionEvent",
            "stepName": "Generate snapshot step",
            "createdAt": "2021-08-25T09:10:30.494Z",
            "newStatus": "STARTED"
          },
          {
            "__typename": "AppDeploymentLogEvent",
            "stepName": "Generate snapshot step",
            "createdAt": "2021-08-25T09:10:30.738Z",
            "message": "Snapshot error occurred: Error: ForgeUI is not defined\nValidation errors: {\n  \"stack\": [\n    \"Error: Snapshot error occurred: Error: ForgeUI is not defined\",\n    \"    at /var/task/index.js:65634:27\"\n  ]\n}",
            "level": "WARNING"
          },
          {
            "__typename": "AppDeploymentTransitionEvent",
            "stepName": "Generate snapshot step",
            "createdAt": "2021-08-25T09:10:30.741Z",
            "newStatus": "FAILED"
          }
        ]
      },
      {
        "description": "Deploying to environment",
        "events": []
      }
    ]
  }
}
ℹ Validating manifest
  Upload URL is valid
  Found manifest file
  Manifest is a valid YAML
  Manifest passed common validations
  Manifest doesn't have forbidden modules
  Manifest passed function names validations
  Manifest passed cleanup function validation
ℹ Snapshotting functions
  Snapshot error occurred: Error: ForgeUI is not defined
Validation errors: {
  "stack": [
    "Error: Snapshot error occurred: Error: ForgeUI is not defined",
    "    at /var/task/index.js:65634:27"
  ]
}

Error: Error thrown in the snapshot context.
App code snapshot error: Snapshot error occurred: Error: ForgeUI is not defined
Learn more about the snapshot context at http://go.atlassian.com/forge-snapshot-context.

Error: Error thrown in the snapshot context.
App code snapshot error: Snapshot error occurred: Error: ForgeUI is not defined
Learn more about the snapshot context at http://go.atlassian.com/forge-snapshot-context.
    at ArtifactDeployer.handleErrorEvent (/home/gt/.nvm/versions/node/v14.17.5/lib/node_modules/@forge/cli/out/deploy/deployer/deployer.js:127:23)
    at ArtifactDeployer.pollAndCheckEvents (/home/gt/.nvm/versions/node/v14.17.5/lib/node_modules/@forge/cli/out/deploy/deployer/deployer.js:61:18)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async ArtifactDeployer.monitorDeployment (/home/gt/.nvm/versions/node/v14.17.5/lib/node_modules/@forge/cli/out/deploy/deployer/deployer.js:72:28)
    at async ArtifactDeployer.deploy (/home/gt/.nvm/versions/node/v14.17.5/lib/node_modules/@forge/cli/out/deploy/deployer/deployer.js:36:9)
    at async PackageUploadDeployCommand.execute (/home/gt/.nvm/versions/node/v14.17.5/lib/node_modules/@forge/cli/out/deploy/package-upload-deploy.js:14:9)
    at async CommandLineUI.displayProgress (/home/gt/.nvm/versions/node/v14.17.5/lib/node_modules/@forge/cli/node_modules/@forge/cli-shared/out/ui/command-line-ui.js:44:28)
    at async DeployView.reportDeploymentProgress (/home/gt/.nvm/versions/node/v14.17.5/lib/node_modules/@forge/cli/out/command-line/view/deploy-view.js:50:24)
    at async DeployController.run (/home/gt/.nvm/versions/node/v14.17.5/lib/node_modules/@forge/cli/out/command-line/controller/deploy-controller.js:122:27)
    at async Command.actionProcessor (/home/gt/.nvm/versions/node/v14.17.5/lib/node_modules/@forge/cli/out/command-line/command.js:74:32)

Hi!

I have only two dependencies:

    "@forge/api": "^2.2.1",
    "@forge/ui": "^0.15.0"

Packages are upgraded to the latest version.

Hi,
Could you post the first few lines of your app where you have the import statements?

Matt

Hi!

Sure. I can post a whole index.jsx which does not work:

import { Fragment, ProjectPage, Text, render, useProductContext, useState } from "@forge/ui";
import api, { route } from "@forge/api";

const fetchWorklogs = async () => {
    const res = await api
    .asUser()
    .requestJira(route`/rest/api/3/worklog/list`);

    return await res.json();
};

const WorklogList = ({ items }) =>
    items.length > 0 && (
        <Fragment>
            {items.map((item) => (
                <Text>
                    Worked {item.timeSpent} on {item.issueId}
                </Text>
                ))}
        </Fragment>
    );

const App = () => {
    const context = useProductContext();
    const [worklogs] = useState(async () => await fetchWorklogs());

    console.log(`Number of worklogs you reported: ${worklogs.length}`);

    return (
        <Fragment>
            <WorklogList items={worklogs}/>
        </Fragment>
    );
};

export const run = render(
    <ProjectPage>
        <App/>
    </ProjectPage>
);

Here is the manifest:

modules:
  jira:projectPage:
    - key: worklog-project-page
      function: main
      title: Worklog
  function:
    - key: main
      handler: index.run
app:
  id: ari:cloud:ecosystem::app/47445c04-1d74-4dfa-a043-2120d4cd664b
  runtime:
    snapshots: true
permissions:
  scopes:
    - read:jira-work
    - read:me

Add “ForgeUI” to the UI call

import ForgeUI, { Fragment, ProjectPage, Text, render, useProductContext, useState } from "@forge/ui";
3 Likes

Wow, this solved it! I was thinking on something similar, however I didn’t found the object name “ForgeUI” in the source code so I was thinking it will be unresolved, so the referencing to it will be the problem.

Wrong

It wasn’t required some days ago.
Obviously the added import will be unused in my code, so I guess the deployment process adds something which using it. If it’s a new dependence, then that process may add this import. If not, then it was added before, but something broke there. So I regard this as a just a workaround until further fix.

Anyway, I’m happy with this.

Thanks for the help!

EDIT: :scream_cat: Yay, it is all over the ForgeUI documentation. So yea, it seems I didn’t realized that my problems started when I used the first ForgeUI component…

1 Like