Skip to content

Fix top-level await in skill code examples #97

@marc0olo

Description

@marc0olo

Context

Identified in #95 (comment): the build.target: "esnext" recommendation proposed in #95 is unnecessary. The real issue is that skill code examples use bare top-level await, which fails with Vite's default build target (es2020).

Problem

Three skills have await at module scope in their code blocks. When an agent copies these into a Vite-bundled module, the build fails with "Top-level await is not available in the configured target environment".

Affected skills:

  • internet-identity/SKILL.mdawait AuthClient.create(), await authClient.isAuthenticated()
  • wallet-integration/SKILL.mdawait IcrcWallet.connect(...)
  • asset-canister/SKILL.mdawait HttpAgent.create(...)

Fix

Wrap all top-level await examples in async functions:

async function init() {
  const authClient = await AuthClient.create();
  // ...rest of auth flow
}
init();

This works with any Vite build target and is more realistic — real apps initialize inside lifecycle hooks or init functions, not at module scope.

Acceptance criteria

  • All await in code blocks across the three skills are inside functions
  • npm run validate passes
  • No build.target: "esnext" added anywhere

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions