Skip to content

Local World: "Cannot find module 'local'" error with Turbopack (Next.js 16) #383

@waldhari1

Description

@waldhari1

Summary

After installing the PR #373 fix (related to #367), we encounter a new error when executing workflows in Local World:

Error: Cannot find module 'local'
Require stack:
- /home/waldhari/software-packages/waltoria/apps/advisor-activity-nexus/index.js
    at module evaluation (app/api/workflows/trigger/[workflowName]/route.ts:16:1)
> 16 | import { start } from 'workflow/api'

Background

Root Cause Analysis

Traced to @workflow/core/dist/runtime/world.js:

// Line 5: Creates require relative to index.js
const require = createRequire(join(process.cwd(), 'index.js'));

// Line 20: Determines target world
const targetWorld = process.env.WORKFLOW_TARGET_WORLD || defaultWorld();

// Line 37: If not 'embedded' or 'vercel', tries to require() as module
const mod = require(targetWorld);

Problem: During Turbopack bundling/runtime, targetWorld appears to resolve to the string 'local' instead of 'embedded', causing require('local') to fail.

Environment

  • Next.js: 16.0.0 (Turbopack - default bundler)
  • Project: Turbo monorepo
  • Runtime: Local World (development)
  • OS: WSL2 Ubuntu
  • Node: v22.x
  • Package Manager: pnpm

Configuration

// next.config.mjs
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const { withWorkflow } = require('workflow/next');

export default withWorkflow(nextConfig);

No WORKFLOW_TARGET_WORLD environment variable is set (should default to 'embedded').

Reproduction Steps

  1. Create a Next.js 16 app with Turbopack in a Turbo monorepo
  2. Install workflow package: pnpm add https://workflow-docs-git-fix-gh-367.vercel.sh/workflow.tgz
  3. Create a workflow with default export
  4. Create an API route that imports { start } from 'workflow/api'
  5. Start dev server: pnpm dev
  6. Make a POST request to trigger the workflow
  7. Observe Cannot find module 'local' error

Observations

  1. ✅ Server starts successfully
  2. ✅ Workflow directives are discovered
  3. ✅ Steps bundle created
  4. ❌ Error occurs only when invoking a workflow via API route
  5. @workflow/world-local package IS installed correctly

Expected Behavior

targetWorld should resolve to 'embedded' and use createEmbeddedWorld() for Local World development.

Actual Behavior

targetWorld resolves to 'local', causing require('local') which fails because no such module exists.

Questions

  1. Is this a known Turbopack-specific issue?
  2. Is there a workaround for Local World module resolution?
  3. Should we test in Vercel World instead to validate the PR Fix default export workflow function transformation in workflow mode #373 fix?

Related

Thanks! 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions