Skip to content

Build fails when using src/actions/index.ts #16933

Description

@madaboutbrighton

Astro Info

Astro                    v6.4.2
Vite                     v7.3.3
Node                     v24.14.1
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  @astrojs/cloudflare (v13.6.0)
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

On a clean install, build is successful, using npm run build

However, as soon as i create a src/actions/index.ts file, the build fails with the following error.

14:17:10 [@astrojs/cloudflare] Enabling compile-time image optimization. Images will be pre-optimized at build time.
14:17:10 [@astrojs/cloudflare] Enabling sessions with Cloudflare KV with the "SESSION" KV binding.
14:17:10 [vite] ✨ optimized dependencies changed. reloading
14:17:10 [vite] [vite] program reload
The file does not exist at "/var/www/html/astro-empty/node_modules/.vite/deps_ssr/chunk-HCV7IJIU.js?v=91134c92" which is in the optimize deps directory. The dependency might be incompatible with the dep optimizer. Try adding it to `optimizeDeps.exclude`.
  Stack trace:
    at runInRunnerObject (workers/runner-worker/index.js:107:3)
    at null.<anonymous> (workers/runner-worker/index.js:350:37)

Here is my simple src/actions/index.ts file...

import { defineAction } from "astro:actions";
import { z } from "astro/zod";

export const server = {
  actionFormTest: defineAction({
      accept: "form",

      input: z.object({
          name: z.string(),
          email: z.email(),
          message: z.string().min(10).max(500),
      }),

      handler: async (input) => {

          console.log("Received contact form actionFormTest:", { name: input.name, email: input.email, message: input.message });

          try {
              // Simulate processing the form data, e.g. sending an email.
              console.log("Do something with the data, e.g. send an email or save to database");
          } catch (e) {
              // Handle any errors that occur during processing.
              console.error("Error processing contact form:", e);
              throw new Error("Failed to process the contact form. Please try again later.");
          }
      },
  })
}

If i remove index.ts then the build succeeds.

Thank you very much in advance for any help you can provide.

What's the expected result?

The build should succeed.

Link to Minimal Reproducible Example

https://github.com/madaboutbrighton/astro-empty

Participation

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

Metadata

Metadata

Assignees

Labels

- P3: minor bugAn edge case that only affects very specific usage (priority)pkg: cloudflareRelated to the Cloudflare adaptertriage: unable to fixBug reproduced and diagnosed, but no fix was found

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions