#17651·vercel

[services] @vercel/backends makes an outputDirectory that holds the entrypoint the function root, so a pnpm workspace service cannot load

Author: klanthierCreated Sep 25, 2026Updated Sep 25, 2026

Environment

  • Vercel Services (Beta), Vercel CLI 59.25.4 with @vercel/backends 8.0.2. The builder code in dist/index.mjs is the same in 10.0.0, pinned by CLI 60.0.1.
  • pnpm 10 workspace. The service lives below the repository root (root: "apps/api").
  • NestJS 12 app, ESM ("type": "module" in apps/api/package.json), Node 24.

Configuration

json
{
  "services": {
    "api": {
      "root": "apps/api",
      "framework": "nestjs",
      "buildCommand": "pnpm build",
      "outputDirectory": "dist"
    }
  },
  "rewrites": [{ "source": "/(.*)", "destination": { "service": "api" } }]
}

pnpm build runs nest build and writes apps/api/dist/main.js.

What happens

  • The build succeeds, but every request fails. The function log shows:

    Warning: Failed to load the ES module: /var/task/main.js. Make sure to set "type": "module" in the nearest package.json file or use the .mjs extension.
    SyntaxError: Cannot use import statement outside a module
  • maybeDoBuildCommand finds main.js in dist and globs dist/** relative to dist. So the function's filePathMap puts main.js at the root (main.js -> apps/api/dist/main.js). The traced dependencies keep their repository paths (node_modules/.pnpm/…, apps/api/node_modules/…).

  • /var/task/main.js therefore has no package.json with "type": "module" beside it, and its bare imports cannot resolve. A local copy of the function filesystem shows the same failure: ERR_MODULE_NOT_FOUND: Cannot find package 'reflect-metadata' imported from …/main.js.

  • Leaving outputDirectory unset gives the same layout, because the builder then searches dist, build and output after the build command.

  • Naming the built file instead ("entrypoint": "dist/main.js") is rejected before the build: Service "api" has entrypoint "dist/main.js" but that path does not exist. The builder itself finds the entrypoint after the build command (#17284), but the services resolver checks for it before the build.

Expected

  • Either keep the output directory's files at their repository path, as the @vercel/nestjs wrapper does (it returns join(dir, entrypointFromOutputDir), so the handler stays at dist/main.js beside the service's package.json and node_modules),
  • or accept a service entrypoint that the build command creates.

Workaround "entrypoint": "src/main.ts" together with "outputDirectory": "." makes the builder compile the source instead of reusing dist. The "." behaviour is from #16761. Without ".", a dist left in the tree is picked up again.

Reproduction

  1. Create a pnpm workspace with apps/api: a NestJS app with "type": "module", src/main.ts calling app.listen(), and "build": "nest build".
  2. Add the vercel.json above at the repository root, and set the project framework to Services.
  3. Run vercel build. Then open .vercel/output/services/api/functions/index.func/.vc-config.json: handler is main.js and filePathMap maps it to apps/api/dist/main.js. Deploy, and request any path.