Skip to content

[bug] Evlog Nitro v3 adapter triggers Bun package-manager cache writes on Vercel runtime #312

@gtothesquare

Description

@gtothesquare

evlog version

2.14.0

Runtime & OS

bun 1.3.13

Framework / integration

TanStack Start

Adapter or drain (optional)

posthog

Description

When using evlog/nitro/v3 in a TanStack Start / Nitro v3 app deployed to Vercel with Bun runtime, requests fail at runtime with:

error: bun is unable to write files: ReadOnlyFileSystem
Bun process exited with exit status: 1

This appears to be caused by Evlog runtime config discovery probing optional nitropack modules with dynamic imports. Under Bun on Vercel, the missing optional dynamic import can trigger Bun package-manager/cache behavior, which attempts to create/write node_modules/.cache in Vercel’s read-only function filesystem.

Tried with bunfig.toml config

[install]
auto = "disable"

but didn't work.

Expected behavior

In a Nitro v3 app, Evlog should not trigger runtime package resolution for missing optional Nitro 2 / nitropack modules.

If config was already passed to evlog(evlogConfig) in nitro.config.ts, the runtime plugin and adapters should be able to use that config without probing missing optional packages.

Actual behavior

At Vercel runtime, every request failed with:

error: bun is unable to write files: ReadOnlyFileSystem
Bun process exited with exit status: 1

This happened before app-level logs were produced.

As said before, adding a repo-level bunfig.toml did not fix it:

[install]
 auto = "disable"

I was able to avoid the runtime failure by (actually it was codex that found the solution :D ):

  1. Setting process.env.__EVLOG_CONFIG before Evlog’s Nitro plugin initializes.
  2. Avoiding createPostHogDrain() because it calls the runtime config bridge even when apiKey and host are passed directly.
  3. Calling sendBatchToPostHog() directly from a custom drain pipeline.

Example workaround:

  // server/plugins/evlog-runtime-config.ts
  import { definePlugin } from 'nitro';

  const evlogConfig = {
    env: {
      service: 'web',
      environment:
        process.env.VERCEL_ENV === 'preview'
          ? 'preview'
          : process.env.NODE_ENV === 'production'
            ? 'production'
            : 'development',
    },
  };

  export default definePlugin(() => {
    process.env.__EVLOG_CONFIG ??= JSON.stringify(evlogConfig);
  });

Reproduction

  1. Create a TanStack Start app using Nitro v3 and Bun.

  2. Install Evlog:

bun add evlog
  1. Add Evlog’s Nitro v3 module:
// nitro.config.ts
 import { defineConfig } from 'nitro';
 import evlog from 'evlog/nitro/v3';

 const evlogConfig = {
   env: {
     service: 'repro-app',
     environment: 'preview',
   },
 };

 export default defineConfig({
   experimental: {
     asyncContext: true,
   },
   modules: [evlog(evlogConfig)],
 });
  1. Add a PostHog drain using explicit config:
// server/plugins/evlog-drain.ts
 import { definePlugin } from 'nitro';
 import { createPostHogDrain } from 'evlog/posthog';

 export default definePlugin((nitroApp) => {
   nitroApp.hooks.hook(
     'evlog:drain',
     createPostHogDrain({
       apiKey: process.env.POSTHOG_API_KEY!,
       host: '...',
     }),
   );
 });
  1. Register the plugin:
// nitro.config.ts
 export default defineConfig({
   experimental: {
     asyncContext: true,
   },
   plugins: ['./server/plugins/evlog-drain'],
   modules: [evlog(evlogConfig)],
 });
  1. Configure Vercel to use Bun runtime:
  // vercel.json
  {
    "bunVersion": "1.x"
  }
  1. Deploy to a Vercel preview environment with POSTHOG_API_KEY set.
  2. Open the deployed preview URL.

Expected result: the app renders normally and Evlog drains logs to PostHog.

Actual result: the Vercel function fails at runtime with:

error: bun is unable to write files: ReadOnlyFileSystem
Bun process exited with exit status: 1

Adding this did not resolve the runtime error:

# bunfig.toml
[install]
auto = "disable"

Logs or structured output (optional)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions