ComposioHQ/composio · error · Error

File system operations are not supported in this runtime env

Error message

File system operations are not supported in this runtime environment (Cloudflare Workers/Edge). Use environment variables or external storage services instead.

What it means

In edge runtimes (Cloudflare Workers) the platform shim replaces Node's fs with stubs, and readFileSync always throws because no real filesystem exists in Workers. The library routes any file-read call through this shim, so code paths that read config/state from disk fail fast with a clear message instead of mysteriously failing.

Source

Thrown at ts/packages/core/src/platform/workerd.ts:95

  },

  realpathSync(filePath: string): string {
    // No filesystem in edge runtimes: cannot resolve symlinks, so return the
    // input unchanged. Local-path uploads don't happen on workerd anyway.
    return filePath;
  },

  isFileSystemCaseSensitive(_filePath: string): boolean {
    // Preserve exact matching when there is no filesystem to inspect.
    return true;
  },

  mkdirSync(_dirPath: string): void {
    // No-op in edge runtimes - directories cannot be created
  },

  readFileSync(_filePath: string, _encoding?: Uint8ArrayEncoding): never {
    throw new Error(
      'File system operations are not supported in this runtime environment (Cloudflare Workers/Edge). ' +
        'Use environment variables or external storage services instead.'
    );
  },

  writeFileSync(
    _filePath: string,
    _content: string | Uint8Array,
    _encoding?: Uint8ArrayEncoding
  ): never {
    throw new Error(
      'File system operations are not supported in this runtime environment (Cloudflare Workers/Edge). ' +
        'Use environment variables or external storage services instead.'
    );
  },
};

View on GitHub (pinned to 64b1b85502)

Solutions

  1. Replace file reads with environment variables (wrangler vars/secrets) or external storage (KV, R2, D1)
  2. Remove fs calls (including in dependencies) from code paths that run on Workers
  3. Test with the Cloudflare runtime (pnpm test:e2e:cloudflare) before deploying

Example fix

// before
const config = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
// after (Cloudflare Workers)
const config = JSON.parse(env.COMPOSIO_CONFIG_JSON);
Defensive patterns

Strategy: fallback

Validate before calling

if (typeof (globalThis as any).WebSocketPair !== 'undefined' || navigator?.userAgent?.includes('Cloudflare-Workers')) {
  // edge runtime: read from env instead of fs
  config = JSON.parse(env.COMPOSIO_CONFIG_JSON);
} else {
  config = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
}

Type guard

const isEdgeRuntime = (): boolean => typeof (globalThis as any).WebSocketPair !== 'undefined';

Try / catch

try { data = readFileSync(path, 'utf8'); } catch (e) { if (/not supported in this runtime/.test((e as Error).message)) { data = env[envKey]; } else throw e; }

Prevention

When it happens

Trigger: Deploying @composio/core (or code that calls its fs-using paths, e.g. file-based config/API-key loading) to Cloudflare Workers/edge, where the platform/workerd.ts shim is selected and readFileSync is invoked at runtime.

Common situations: Porting a Node service that reads a config file or .env-like file to Workers, local dev working (Node shim) while deployed Workers build throws, or a dependency assuming fs availability.

Related errors


AI-assisted analysis of ComposioHQ/composio@64b1b85502 (2026-08-28). Data as JSON: /api/errors/848e83854f02aacd. Report an issue: GitHub.