Skip to content

Cannot resolve SvelteKit virtual modules ($env/static/private) in workflow files #566

@pheuter

Description

@pheuter

Description

When defining a workflow that imports from a SvelteKit app's server modules, the workflow plugin fails to resolve SvelteKit's virtual modules like $env/static/private.

Reproduction

  1. Create a SvelteKit app with the workflow plugin configured in vite.config.ts:
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vitest/config';
import { workflowPlugin } from 'workflow/sveltekit';

export default defineConfig({
  plugins: [
    sveltekit(),
    workflowPlugin(),
  ],
});
  1. Create a workflow file in workflows/sample-workflow.ts that imports from a server module:
export async function handleUserSignup(email: string) {
  'use workflow';

  const user = await getUserByEmail(email);
  return { userId: user?.id, status: 'onboarded' };
}

async function getUserByEmail(email: string) {
  'use step';

  const { prisma } = await import('$lib/server/db');
  return await prisma.user.findUnique({ where: { email } });
}
  1. The $lib/server/db module imports from SvelteKit's virtual module:
import { MONGODB_URI } from "$env/static/private";
// ... prisma client setup
  1. Run typecheck or build

Error

✘ [ERROR] Could not resolve "$env/static/private"

    src/lib/server/db.ts:1:28:
      1 │ import { MONGODB_URI } from "$env/static/private";
        ╵                             ~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "$env/static/private" as external to exclude it from the bundle, which
  will remove this error and leave the unresolved path in the bundle.

failed to load config from /path/to/project/apps/app/vite.config.ts
Preprocessing failed
Error: Build failed with 1 error:
src/lib/server/db.ts:1:28: ERROR: Could not resolve "$env/static/private"

Expected Behavior

The workflow plugin should either:

  1. Properly resolve SvelteKit's virtual modules ($env/static/private, $env/dynamic/private, $lib/*, etc.)
  2. Or mark these paths as external during the workflow discovery/bundling phase

Environment

  • Bun
  • esbuild 0.25.12
  • svelte: 5.45.5
  • @sveltejs/kit: 2.49.1
  • workflow: 4.0.1-beta.28

Metadata

Metadata

Assignees

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