Skip to content

expo start crashes when an API route calls console.log (Node < 22.14, Metro index source maps) #50803

Closed

Description

@robhogan

Summary

With web.output: "server", any console.log in an API route kills expo start on the first request that reaches it, on Node before v22.14.0:

TypeError: The "payload" argument must be of type object. Received null
    at cloneSourceMapV3 (node:internal/source_map/source_map:365:3)
    at new SourceMap (node:internal/source_map/source_map:145:21)
    at Object.findSourceMap (node:internal/source_map/source_map_cache:348:17)
    at wrapCallSite (.../@expo/require-utils/build/stacktrace.js:138:30)
    at Error.prepareStackTrace (.../@expo/require-utils/build/stacktrace.js:103:38)
    at prepareStackTraceCallback (node:internal/errors:144:29)
    at getErrorMessage (.../finalhandler/index.js:176:15)

On newer Node it doesn't crash, but stack traces from API routes and server rendering point into the evaluated bundle instead of the original source.

Cause

@expo/require-utils gives Node the server bundle's source map through a sourceMappingURL file. Since Metro 0.87 (#50135), that map is an index map (sections, no top-level sources), which Node can't load from a file. Node caches an entry with a null payload for the module.

  • Before lib: suppress source map lookup exceptions nodejs/node#56299 (v22.14.0, v23.6.0), module.findSourceMap throws for such a module instead of returning undefined. The console.log override in serverLogLikeMetro captures a stack, so prepareStackTrace throws from inside the route handler. The error handler then formats that error's stack, which throws again, uncaught.
  • On any Node version, the bundle has no usable source map, so frames are left unmapped.

Repro

SDK 58 (expo@58.0.0-preview.7, expo-router@58.0.8), Node v22.13.1:

  1. Set web.output to "server".
  2. Add app/api/log+api.ts:
    export function GET() {
      console.log('hello');
      return Response.json({});
    }
  3. Run npx expo start and request /api/log. The process exits with the error above.

Fix

Two changes, on branch robhogan/cli-flatten-eval-source-map, PRs to follow:

  • @expo/require-utils: treat a throwing findSourceMap like a missing map and fall back to the unmapped frame.
  • @expo/cli: flatten the map with flattenSourceMap before evalModule, as the export path in MetroBundlerDevServer already does, so Node gets a map it can load and frames map to source again.

Activity

  1. expo-bot commented on Sep 29, 2026

    @expo-bot
    Collaborator

    Hi there! It looks like your issue requires a minimal reproducible example, but it is invalid or absent. Please prepare such an example and share it in a new issue.

    The best way to get attention to your issue is to provide a clean and easy way for a developer to reproduce the issue on their own machine. Please do not provide your entire project, or a project with more code than is necessary to reproduce the issue.

    A side benefit of going through the process of narrowing down the minimal amount of code needed to reproduce the issue is that you may get lucky and discover that the bug is due to a mistake in your application code that you can quickly fix on your own.

    Resources

    Common concerns

    "I've only been able to reproduce it in private, proprietary code"

    You may not have spent enough time narrowing down the root cause of the issue. Try out the techniques discussed in this manual debugging guide to learn how to isolate the problem from the rest of your codebase.

    "I didn't have time to create one"

    That's understandable, it can take some time to prepare. We ask that you hold off on filing an issue until you are able to fully complete the required fields in the issue template.

    "You can reproduce it by yourself by creating a project and following these steps"

    This is useful knowledge, but it's still valuable to have the resulting project that is produced from running the steps, where you have verified you can reproduce the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions