Skip to content

Conversation

@TooTallNate
Copy link
Member

@TooTallNate TooTallNate commented Nov 20, 2025

Fixed a bug where default export workflow functions with names (e.g., export default async function testWorkflow()) would fail at runtime with ReferenceError: $$default is not defined. The SWC plugin now correctly keeps the default export as-is and simply adds the workflowId assignment after it, since the function name is available as a binding in the module scope.

Also adds support for anonymous and arrow function default exports, which previously were not being transformed at all.

Fixes #367.

Fixed a bug where default export workflow functions with names (e.g., `export default async function testWorkflow()`) would fail at runtime with `ReferenceError: $$default is not defined`. The SWC plugin now correctly keeps the default export as-is and simply adds the workflowId assignment after it, since the function name is available as a binding in the module scope.

Fixes #367.
@changeset-bot
Copy link

changeset-bot bot commented Nov 20, 2025

🦋 Changeset detected

Latest commit: dfa4112

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@workflow/swc-plugin Patch
@workflow/builders Patch
@workflow/cli Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/sveltekit Patch
workflow Patch
@workflow/world-testing Patch
@workflow/nuxt Patch
@workflow/ai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@TooTallNate TooTallNate requested a review from Schniz November 20, 2025 01:21
@vercel
Copy link
Contributor

vercel bot commented Nov 20, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
example-nextjs-workflow-turbopack Ready Ready Preview Comment Nov 20, 2025 5:47pm
example-nextjs-workflow-webpack Ready Ready Preview Comment Nov 20, 2025 5:47pm
example-workflow Ready Ready Preview Comment Nov 20, 2025 5:47pm
workbench-express-workflow Ready Ready Preview Comment Nov 20, 2025 5:47pm
workbench-hono-workflow Ready Ready Preview Comment Nov 20, 2025 5:47pm
workbench-nitro-workflow Ready Ready Preview Comment Nov 20, 2025 5:47pm
workbench-nuxt-workflow Ready Ready Preview Comment Nov 20, 2025 5:47pm
workbench-sveltekit-workflow Ready Ready Preview Comment Nov 20, 2025 5:47pm
workbench-vite-workflow Ready Ready Preview Comment Nov 20, 2025 5:47pm
workflow-docs Ready Ready Preview Comment Nov 20, 2025 5:47pm

@TooTallNate TooTallNate marked this pull request as ready for review November 20, 2025 02:31
@@ -0,0 +1,8 @@
// Test anonymous default export workflow
/**__internal_workflows{"workflows":{"input.js":{"default":{"workflowId":"workflow//input.js//defaultWorkflow"}}}}*/;
const defaultWorkflow = async function() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const defaultWorkflow = async function() {
const __default = async function() {

Comment on lines 7 to 8
defaultWorkflow.workflowId = "workflow//input.js//defaultWorkflow";
export default defaultWorkflow;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
defaultWorkflow.workflowId = "workflow//input.js//defaultWorkflow";
export default defaultWorkflow;
defaultWorkflow.workflowId = "workflow//input.js//__default";
export default __default;

@@ -1,5 +1,5 @@
// Test workflow functions in client mode
/**__internal_workflows{"workflows":{"input.js":{"arrowWorkflow":{"workflowId":"workflow//input.js//arrowWorkflow"},"defaultWorkflow":{"workflowId":"workflow//input.js//defaultWorkflow"},"internalWorkflow":{"workflowId":"workflow//input.js//internalWorkflow"},"myWorkflow":{"workflowId":"workflow//input.js//myWorkflow"}}}}*/;
/**__internal_workflows{"workflows":{"input.js":{"arrowWorkflow":{"workflowId":"workflow//input.js//arrowWorkflow"},"default":{"workflowId":"workflow//input.js//defaultWorkflow"},"internalWorkflow":{"workflowId":"workflow//input.js//internalWorkflow"},"myWorkflow":{"workflowId":"workflow//input.js//myWorkflow"}}}}*/;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like a bug no? the function here is called defaultWorkflow

Comment on lines 11 to 13
export default async function defaultWorkflow() {
return await process();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting case of exporting a named default workflow

@TooTallNate TooTallNate merged commit e5c5236 into main Nov 20, 2025
21 of 41 checks passed
@TooTallNate TooTallNate deleted the fix/gh-367 branch November 20, 2025 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReferenceError: $$default is not defined - Workflow execution fails in Local World on Turbo monorepo

3 participants