Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

actions: Throw error on missing server output #11028

Merged
merged 5 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/many-news-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Throw on missing server output when using Astro Actions.
12 changes: 12 additions & 0 deletions packages/astro/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@ import type { Plugin as VitePlugin } from 'vite';
import type { AstroIntegration } from '../@types/astro.js';
import { viteID } from '../core/util.js';
import { ACTIONS_TYPES_FILE, RESOLVED_VIRTUAL_MODULE_ID, VIRTUAL_MODULE_ID } from './consts.js';
import { AstroUserError } from '../core/errors/errors.js';

const serverOutputs = ['server', 'hybrid'];

export default function astroActions(): AstroIntegration {
return {
name: VIRTUAL_MODULE_ID,
hooks: {
async 'astro:config:setup'(params) {
if (!serverOutputs.includes(params.config.output)) {
bholmesdev marked this conversation as resolved.
Show resolved Hide resolved
const error = new AstroUserError(
bholmesdev marked this conversation as resolved.
Show resolved Hide resolved
'Actions require a server output. Set the \`output\` property in your Astro config.',
'Learn about on-demand rendering: https://docs.astro.build/en/basics/rendering-modes/#on-demand-rendered'
);
error.stack = undefined;
throw error;
}

const stringifiedActionsImport = JSON.stringify(
viteID(new URL('./actions', params.config.srcDir))
);
Expand Down
Loading