Skip to content

Astro Actions: Action Named 'apply' Fails When Defined Outside src/actions/index.ts #13528

@pieter-experience-republic

Description


Astro Action Naming Bug Report

Astro Info

Astro                    v5.5.5
Node                     v22.14.0
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

Browser-Specific?

No response

Bug Description

Issue Summary

When defining an Astro action with the name apply inside a separate file (e.g., src/actions/testactions.ts), an error occurs. However, defining the same action in src/actions/index.ts works correctly.

This behavior is undocumented and should either be fixed or explicitly mentioned in the documentation.

Steps to Reproduce

  1. Create an Astro project.

  2. Define actions in src/actions/index.ts:

    import { testactions } from "./testactions";
    
    export const server = {
      testactions,
    };
  3. Define the action in src/actions/testactions.ts:

    import { defineAction } from "astro:actions";
    import { z } from "astro:schema";
    
    export const testactions = {
      apply: defineAction({
        input: z.object({
          message: z.string(),
        }),
        handler: async (input) => {
          return { success: true };
        },
      }),
    };
  4. Run the Astro project and observe the error:

    [ERROR] Expected handler for action testactions to be a function. Received object.
    

Additional Context

  • This issue does not occur with other action names.
  • Renaming apply to another name (e.g., execute) resolves the problem.
  • The documentation does not mention any naming restrictions for actions.

Expected Behavior

  • The action should work regardless of the file it is defined in, as long as it is correctly imported and structured.

Actual Behavior

  • An error occurs when the action is named apply and defined outside src/actions/index.ts.

Minimal Reproducible Example

[StackBlitz Demo](https://stackblitz.com/edit/github-z5cktexo)

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P3: minor bugAn edge case that only affects very specific usage (priority)feat: actionsRelated to Astro actions (scope)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions