Next.js Discord

Discord Forum

How to use server actions in dev, but strip those files in a static export?

Unanswered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
I'm working on a very specific case where my app runs in an iframe, it's very simple and I'd like everything to be static, but some things are very handy during development, such as server functions and environment variables (which I obviously can't access inside the iframe). So my idea is to strip the server actions when exporting.

I've tried dynamic importing, but it seems that all files are evaluated at build time when running next build with the export output config.

Example below:

let condition = false;
if (condition) {
  const startPollMockImport = await import("./mock/start_poll.mock");
  startPollServerAction = startPollMockImport.default;
}


Consider start_poll.mock is a server action, with the "use server" declared in the first line.

Running next build gives me > Server Actions are not supported with static export. even tho the module is not supposed to be imported at all. Removing that block above builds and exports properly.

0 Replies