Skip to content

[Bug]: Cognee UI Frontend - EvalError in Next.js Middleware when running in Docker #1869

@SteveSmart75

Description

@SteveSmart75

Bug Description

GitHub Issue: Cognee UI Frontend - EvalError in Next.js Middleware when running in Docker

Issue Title

cognee-cli -ui frontend throws "EvalError: Code generation from strings disallowed" in Docker environment


Description

When running the Cognee UI in a Docker container (using cognee/cognee:main image), the Next.js frontend fails to render pages due to an EvalError in the middleware. The backend API starts and works correctly, but the frontend returns HTTP 500 errors.

Environment

  • Cognee Version: 0.4.1-local (from cognee/cognee:main Docker image)
  • Frontend Version: Downloaded from v0.3.7 release tag
  • Node.js: v20.19.6
  • Next.js: 15.3.3
  • Docker: Docker Desktop on macOS (darwin 24.6.0)
  • Container Base: Debian Bookworm (from cognee/cognee:main)

Analysis

The error Code generation from strings disallowed for this context is a security restriction in Node.js Edge Runtime that prevents dynamic code evaluation (like eval() or new Function()). This error originates from src/middleware.ts when compiled and executed in the Next.js edge runtime.

The middleware file likely contains code that:

  • Uses dynamic string evaluation
  • Or uses a library that internally uses eval() or similar

Observed Behavior

Component Status
Backend API (uvicorn) ✅ Working - responds with {"message":"Hello, World, I am alive!"}
Frontend Next.js ❌ 500 Error - middleware compilation fails

Backend Works Correctly

$ curl http://localhost:8000/
{"message":"Hello, World, I am alive!"}

$ curl http://localhost:8000/health
# Returns health status

Relevant Logs

Frontend startup (success until middleware compilation)

[Cognee UI Frontend] Backend URL: http://cognee-api:8000
[Cognee UI Frontend] MCP URL: http://cognee:8001
[Cognee UI Frontend] Waiting for backend to be ready...
[Cognee UI Frontend] Backend is ready!
[Cognee UI Frontend] Starting Next.js on port 3000...

> cognee-frontend@1.0.0 dev
> next dev

 ⚠ You are using a non-standard "NODE_ENV" value in your environment.
   ▲ Next.js 15.3.3
   - Local:        http://localhost:3000
   - Network:      http://10.220.0.17:3000

 ✓ Starting...
 ○ Compiling /middleware ...
 ✓ Compiled /middleware in 3.4s (108 modules)
 ○ Compiling / ...
 ⨯ EvalError: Code generation from strings disallowed for this context

Docker Configuration

# docker-compose.yaml excerpt
cognee-ui:
  image: cognee/cognee:main
  ports:
    - "8003:3000"  # Frontend UI
  environment:
    NEXT_PUBLIC_BACKEND_API_URL: "http://cognee-api:8000"
    NODE_ENV: "production"

Workarounds Attempted

  1. Running backend separately - Backend works fine when run directly with uvicorn
  2. Changing NODE_ENV - Tried "development" and "production", same error
  3. Using cognee-cli -ui - Same middleware error occurs

Possible Causes

  1. src/middleware.ts may contain code incompatible with Edge Runtime
  2. A dependency used in middleware might use eval() internally
  3. Next.js 15.3.3 has stricter Edge Runtime security than earlier versions

Suggested Fix

Review cognee-frontend/src/middleware.ts for:

  • Any usage of eval(), new Function(), or similar dynamic code execution
  • Dependencies that might use string-based code generation
  • Consider marking the middleware to run in Node.js runtime instead of Edge runtime if edge features aren't needed:
// In middleware.ts
export const config = {
  runtime: 'nodejs', // Instead of default 'edge'
}

Or alternatively, ensure all code in middleware is Edge Runtime compatible.

Labels (suggested)

  • bug
  • ui
  • docker
  • next.js

Steps to Reproduce

  1. Use Docker image cognee/cognee:main
  2. Download frontend assets from GitHub release v0.3.7
  3. Run npm install in the frontend directory
  4. Set NEXT_PUBLIC_BACKEND_API_URL to point to a running Cognee API backend
  5. Run npm run dev
  6. Access http://localhost:3000 - returns HTTP 500

Alternatively (via cognee-cli)

  1. Inside a Docker container based on cognee/cognee:main
  2. Run cognee-cli -ui
  3. Backend starts successfully on port 8000
  4. Frontend starts on port 3000 but fails with the same EvalError

Expected Behavior

When running cognee-cli -ui or the Cognee frontend in a Docker container:

  1. The backend API should start and remain running (currently works ✅)
  2. The Next.js frontend should compile successfully without errors
  3. The frontend should be accessible at http://localhost:3000 and render the Cognee UI
  4. Users should be able to interact with datasets, run cognify operations, and visualize knowledge graphs through the web interface

Actual Behavior

  1. The backend API starts correctly and responds to requests ✅
  2. The Next.js frontend begins compilation but fails during middleware execution ❌
  3. Accessing http://localhost:3000 returns HTTP 500 Internal Server Error ❌
  4. The error EvalError: Code generation from strings disallowed for this context is thrown from middleware.ts

Environment

OS: Linux 6.10.14-linuxkit (Docker on macOS)
Node: v20.19.6
Next.js: 15.3.3
Cognee: 0.4.1-local (cognee/cognee:main image)
Python: 3.12.12

Logs/Error Messages

⨯ EvalError: Code generation from strings disallowed for this context
    at <unknown> (.next/server/middleware.js:18)
    at (middleware)/./node_modules/next/dist/build/webpack/loaders/next-middleware-loader.js?absolutePagePath=%2Froot%2F.cognee%2Fui-cache%2Ffrontend%2Fsrc%2Fmiddleware.ts&page=%2Fmiddleware&rootDir=%2Froot%2F.cognee%2Fui-cache%2Ffrontend&matchers=&preferredRegion=&middlewareConfig=e30%3D! (.next/server/middleware.js:18:1)
    at __webpack_require__ (.next/server/edge-runtime-webpack.js:37:33)
    at __webpack_exec__ (.next/server/middleware.js:1043:48)
    at <unknown> (.next/server/middleware.js:1044:37)
    at webpackJsonpCallback (.next/server/edge-runtime-webpack.js:1128:39)
    at <unknown> (.next/server/middleware.js:9:61)

Additional Context

This issue was discovered while setting up Cognee with a custom XTDB 2.0 graph database adapter in a Docker-based development environment. The backend (cognee.api.client) works perfectly; only the frontend has this issue.

Related: cognee-cli -ui subprocess issue

Separately, we also observed that cognee-cli -ui has an issue where the backend subprocess dies silently after startup (no supervision/restart). This is a separate issue but makes Docker deployment challenging. The recommended workaround is to run backend and frontend as separate services rather than using cognee-cli -ui as a process manager.

Pre-submission Checklist

  • I have searched existing issues to ensure this bug hasn't been reported already
  • I have provided a clear and detailed description of the bug
  • I have included steps to reproduce the issue
  • I have included my environment details

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions