Skip to content

withEve dev snapshots cannot resolve parent Next.js path aliases although production builds succeed #1242

Description

@pedro757

Link to a minimal reproduction

https://github.com/pedro757/eve-nextjs-authored-module-error-repro

Steps to reproduce

  1. git clone https://github.com/pedro757/eve-nextjs-authored-module-error-repro.git
  2. cd eve-nextjs-authored-module-error-repro
  3. pnpm install
  4. pnpm dev

Actual Output:

[eve:dev:app-agent] Failed to evaluate authored module:
[eve:dev:app-agent]   .../tools/query-data.ts
Error: eve server process exited before printing its server URL

Current vs. expected behavior

Summary

An Eve agent embedded in a Next.js application worked in production builds but failed during local development because the Eve dev-runtime snapshot changed the effective package boundary.
The agent was configured as a named agent whose root pointed directly to a flat agent directory:

export default withEve(nextConfig, {
  agents: {
    "app-agent": {
      root: "./agents/app-agent",
    },
  },
});

The agent imported application code using aliases from the parent Next.js tsconfig.json:

import { findFirstOrUndefined } from "@/lib/utils";
import { getData } from "#/contabilidad/balance/ver/report-data";

The relevant layout was:
apps/nextjs/
├── package.json
├── tsconfig.json
├── app/
├── lib/
└── agents/
└── app-agent/
├── agent.ts
├── channels/
├── lib/
└── tools/
The aliases were defined in apps/nextjs/tsconfig.json:

{
  "compilerOptions": {
    "paths": {
      "@/*": ["./*"],
      "#/contabilidad/*": ["./app/(app)/contabilidad/*"]
    }
  }
}

Actual behavior

The production Eve build succeeded because the authored module bundler resolved the parent Next.js package and its tsconfig.json.
During eve dev, Eve created a snapshot rooted at the configured flat agent directory:
apps/nextjs/agents/app-agent/.eve/dev-runtime/snapshots/.../
It also generated a minimal package.json inside the snapshotted agent root:

{
  "private": true,
  "type": "module"
}

The parent apps/nextjs/tsconfig.json, app/, and lib/ directories were not part of that snapshot. Consequently, the generated authored module retained unresolved imports:

import { eveAuth } from "@/lib/auth/config";
import { findFirstOrUndefined } from "@/lib/utils";

Node then treated @/lib as a package and failed with:
Error [ERR_MODULE_NOT_FOUND]:
Cannot find package '@/lib' imported from
.../.eve/compile/authored-modules/.mjs
Changing the imports to relative paths did not solve the problem because files outside the configured agent root were still absent from the dev snapshot:
[UNRESOLVED_IMPORT] Could not resolve
'../../../lib/report-server'
This creates a production/dev inconsistency: the production bundler can consume parent application sources, while the dev snapshot cannot.

Expected behavior

One of the following would be preferable:

  1. Dev snapshots should preserve the same package and TypeScript resolution boundary used by the production build.
  2. Files resolved through the parent tsconfig.json should be included in the snapshot.
  3. withEve should reject this layout early with an actionable error explaining that root must be the Eve application root, not a flat agent directory that imports parent application code.

eve version

0.27.6

Environment

OS: Linux 7.1.4-arch1-1
Node: v24.18.0
Package Manager: pnpm v11.13.1

☰eve  v0.27.6
eve Info
========
Resolved application paths and the active message contract.

Application
App Root  /home/pedro/Documents/amableconti
Compile   unavailable

Artifacts
Workflow Build  /home/pedro/Documents/amableconti/node_modules/eve/.eve/workflow-cache/bb51d80a0dbf
Output          /home/pedro/Documents/amableconti/.output

Messaging
Workflow ID  workflow//eve//workflowEntry
Source Dir   /home/pedro/Documents/amableconti/node_modules/eve/dist/src/execution
Create       POST /eve/v1/session
Continue     POST /eve/v1/session/:sessionId
Stream       GET /eve/v1/session/:sessionId/stream

Where does the bug occur?

Local dev (eve dev)

Deployment

local dev environment, production works

Build and runtime logs

[eve:dev:app-agent] Error {
[eve:dev:app-agent]   stack: "Cannot find package '@/lib' imported from ./.eve/dev-runtime/snapshots/ms3ec2xy-02d78ce5-b8c9-41bb-8950-ad17b8292459/source/apps/nextjs/agents/app-agent/.eve/compile/authored-modules/d6487e643eabfcca7259cf81014db92cc41b634a69aa4af49bd3feb3cf2
f3025.mjs\n" +
[eve:dev:app-agent]   '    at Object.getPackageJSONURL (node:internal/modules/package_json_reader:301:9)\n' +
[eve:dev:app-agent]   '    at packageResolve (node:internal/modules/esm/resolve:768:81)\n' +
[eve:dev:app-agent]   '    at moduleResolve (node:internal/modules/esm/resolve:859:18)\n' +
[eve:dev:app-agent]   '    at defaultResolve (node:internal/modules/esm/resolve:992:11)\n' +
[eve:dev:app-agent]   '    at #cachedDefaultResolve (node:internal/modules/esm/loader:701:20)\n' +
[eve:dev:app-agent]   '    at #resolveAndMaybeBlockOnLoaderThread (node:internal/modules/esm/loader:721:38)\n' +
[eve:dev:app-agent]   '    at ModuleLoader.resolveSync (node:internal/modules/esm/loader:759:56)\n' +
[eve:dev:app-agent]   '    at #resolve (node:internal/modules/esm/loader:683:17)\n' +
[eve:dev:app-agent]   '    at ModuleLoader.getOrCreateModuleJob (node:internal/modules/esm/loader:603:35)\n' +
[eve:dev:app-agent]   '    at ModuleJob.syncLink (node:internal'... 31 more characters,
[eve:dev:app-agent]   code: 'ERR_MODULE_NOT_FOUND',
[eve:dev:app-agent]   message: "Cannot find package '@/lib' imported from 
[eve:dev:app-agent]   ./.eve/dev-runtime/snapshots/ms3ec2xy-02d78ce5-b8c9-41bb-8950-ad17b8292459/source/apps/nextjs/agents/app-agent/.eve/compile/authored-modules/d6487e643eabfcca7259cf81014db92cc41b634a69aa4af49bd3feb3cf2f3025.mjs",
[eve:dev:app-agent] }

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingbuildp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions