---
title: "Invalid output directory and NoSuchKey 404s on Launch"
url: "https://developers.contentstack.com/guides/fix-failing-launch-builds/output-directory-monorepos-and-404s"
type: "guide_chapter"
level: "intermediate"
intent: "fix"
outcome: "Launch finds your build output, deep links in a single-page app load, and your monorepo app builds and deploys on its own."
prerequisites:
  - "A Launch environment whose deployment fails at packaging or serves 404s after going live"
  - "The build command and output directory your framework uses"
tags:
  - "headless"
  - "cli"
  - "next"
authors:
  - "Tim Benniks"
published: "2026-11-15T10:55:34.413Z"
updated: "2026-11-15T10:55:34.413Z"
---

# Invalid output directory and NoSuchKey 404s on Launch

- **Authors:** Tim Benniks
- **Published:** 2026-11-15T10:55:34.413Z
- **Level:** Intermediate
- **Intent:** Fix
- **Tags:** headless, cli, next

---

The build log says the build succeeded. All your routes were generated. Then the deployment fails with Invalid output directory, or it goes live and the first deep link returns NoSuchKey. Both mean the same thing from Launch's side: it can't find the files it's supposed to serve where you told it to look.

This chapter covers single apps first, then single-page apps, then monorepos, where most of these problems live.

## What you'll learn

- How the Output Directory setting maps to what your build writes


- Why single-page apps return NoSuchKey on refresh and how to add a fallback


- How to deploy one app from a Turborepo or Nx monorepo


- Which package managers Launch supports



## Symptoms

- The build step finishes, then packaging fails:



```text
Warning: Invalid output directory: ./apps/web/.next
Deployment failed: Please try to redeploy the site, or contact support for assistance.
```

- The site is live, but a page returns an XML-style error:



```text
NoSuchKey: The specified key does not exist.
```

- The home page loads, but refreshing /about or opening it from a link in an email returns a 404 or NoSuchKey.


- A deployment runs for a very long time before failing with NoSuchKey, while the same build with the right settings finishes in a few minutes.


- A filtered monorepo build also builds, and fails on, an app you didn't ask for.


- The log shows npm install even though your project uses pnpm.



## Why it happens

Launch concept: each environment has a Framework Preset, a Build Command and an Output Directory. Launch runs the build command from the repository root, then packages whatever is in the output directory. Static files are served from storage, and server workloads such as Next.js SSR run from the packaged server output.

NoSuchKey is the storage layer telling you a requested file doesn't exist. Invalid output directory is the packaging step telling you the folder doesn't contain what the preset expects. Either way, the build put its files somewhere other than where Launch looks, or the files Launch needs were never produced.

## Fix it

### Match the output directory to your build

Check where your build actually writes. Run it locally and look:

```bash
npm run build && ls
```

Common values:

Framework

Output Directory

Next.js

./.next

Create React App

./build

Vite (React, Vue, Svelte)

./dist

Angular

the outputPath in angular.json, for example ./dist/my-app/browser

Gatsby

./public

Set it under the environment's Settings > Build and Output Settings, keep the Framework Preset that matches your framework, and redeploy. For a Next.js app, don't switch the preset to Other to get past an error. That serves the output as a static site, and an App Router app then returns "page does not exist" for every route.

### Add a fallback for single-page apps

A React, Vue or other client-side app with BrowserRouter-style routing has one real file: index.html. When a visitor requests /about directly, Launch looks for a file at that path, doesn't find one, and returns NoSuchKey. Navigating inside the app works, because the router handles it without a request.

Add a catch-all rewrite to launch.json at the repository root so unknown paths serve index.html:

```json
{
  "rewrites": [
    {
      "source": "/:path(.*)",
      "destination": "/index.html"
    }
  ]
}
```

Keep it as the last rewrite in the array, because rules run in order. Real files such as your JavaScript bundles and images must still load, so check the network tab after deploying. If they come back as HTML, narrow the source, for example with a negative lookahead that excludes your assets folder. [Routing with launch.json](/guides/launch-edge-functions-redirects-and-caching/routing-with-launch-json) covers the pattern syntax.

The fallback alternative is a hash router (/#/about), which never asks the server for the path. It works everywhere but changes your URLs.

### Deploy one app from a Turborepo monorepo

Launch has no root directory setting. You select the whole repository and scope the build to one app:

- Build Command: npm run build -- --filter=web


- Output Directory: ./apps/web/.next



npm run build on its own builds every app in the repository, so the filter matters. If the filtered build still pulls in, and fails on, another package, check two things:

- The filter name matches the name in the app's package.json.


- Every workspace package the app imports is declared as a dependency in that app's package.json. Turborepo scopes the build from the declared graph, and an undeclared import that resolves locally can fail on Launch.



```json
{
  "name": "web",
  "dependencies": {
    "@repo/ui": "workspace:*"
  }
}
```

### Next.js in a monorepo: build standalone output

Launch packages Next.js server workloads from Next.js standalone output. In a monorepo it expects that output inside the app's .next folder. When the deployment fails at packaging with Invalid output directory even though the path is correct and the build generated every route, the standalone build is usually missing. Turborepo's strict environment mode filters variables that aren't listed in turbo.json, which can stop the standalone build from being produced.

Set it explicitly in the app's Next.js config:

```js
// apps/web/next.config.js
module.exports = {
  output: 'standalone',
};
```

Check locally that apps/web/.next/standalone exists after npm run build -- --filter=web, then redeploy.

### Nx: keep output inside the app folder

Nx builds to dist/apps/<app> by default. Launch doesn't support build output outside the app's source directory, so change the app's outputPath:

```json
{
  "targets": {
    "build": {
      "executor": "@nx/next:build",
      "options": {
        "outputPath": "apps/my-app"
      }
    }
  }
}
```

Then use Build Command npx nx build my-app and Output Directory ./apps/my-app/.next, with the Next.js preset. Run npx nx reset before testing locally so a cached build doesn't hide the change.

### Monorepo limits to know

- launch.json inside an app folder isn't supported. Keep it at the repository root.


- Cloud Functions from an app's functions directory aren't supported in a monorepo. Use your framework's API routes instead.


- Gatsby apps inside a monorepo aren't supported.



### Use a supported package manager

Launch supports npm (the default) and yarn in node-modules mode. It reads the packageManager field in package.json to pick yarn and its version. pnpm isn't supported: Launch falls back to npm, which ignores pnpm-lock.yaml and resolves fresh versions, so a build that works locally can fail or behave differently. Yarn Plug'n'Play isn't supported either.

If you're on pnpm, generate a package-lock.json with npm install and commit it, or move the project to yarn with nodeLinker: node-modules in .yarnrc.yml.

## Check that it worked

- The deployment log reaches the packaging step without Invalid output directory.


- Request a deep link directly and check the status:



```bash
curl -sI https://your-site.contentstackapps.com/about | head -n 1
```

You want HTTP/2 200. Also request a real asset, such as your main JavaScript file, and confirm its content-type isn't text/html.

- For a monorepo, the build output in the log lists only the app you filtered to.



## Prevent it

- Write the build command and output directory into your README, so the next environment uses the same values.


- Add the SPA fallback rewrite when you create the project, not after the first broken link.


- Declare every internal workspace dependency in the consuming app's package.json.


- Set output: 'standalone' for every Next.js app in a monorepo.


- Commit one lockfile that matches a supported package manager.



## Key takeaways

- Invalid output directory and NoSuchKey mean Launch can't find the files where the Output Directory points.


- Single-page apps need a final /:path(.*) to /index.html rewrite in launch.json, or a hash router.


- In a monorepo, the filtered build command plus the app's output directory replace a root directory setting.


- Next.js apps in a monorepo need output: 'standalone'; Nx apps need their outputPath inside the app folder.


- Launch supports npm and yarn in node-modules mode. pnpm falls back to npm.



If the deployment now succeeds but the site returns CF errors or timeouts, continue with [Launch error codes decoded](/guides/launch-error-codes-decoded).



---

## Do this with AI

Install the launch-platform skill from [Contentstack agent skills](https://github.com/contentstack/contentstack-agent-skills). Then ask your agent:

> This repository is a monorepo deployed to Launch. Read package.json, turbo.json or nx.json, the app's next.config.js and the lockfiles, and propose the Framework Preset, Build Command and Output Directory for the app in apps/web. Flag anything Launch doesn't support, such as pnpm, output outside the app folder or launch.json inside the app.

New to this? [Set up your AI workbench](/guides/set-up-your-ai-workbench-for-contentstack) first.




---

## Frequently asked questions

### What does NoSuchKey The specified key does not exist mean on Launch?

Launch looked for a file that isn't in the deployed output. Either the output directory points at the wrong folder, or a single-page app has no fallback to index.html for client-side routes.

### Is there a root directory setting for monorepos on Launch?

No. You scope the build command to one app, for example npm run build -- --filter web, and set the output directory to that app's build folder, for example ./apps/web/.next.

### Does Launch support pnpm?

No. Launch supports npm and yarn in node-modules mode. A project set up for pnpm falls back to npm, so commit a package-lock.json or switch to yarn.

### Can I deploy an Nx app that builds to dist/apps/my-app?

Not with that default. Launch doesn't support build output outside the app's source directory. Change the Nx outputPath so the build lands inside apps/my-app.



---

## Chapter Navigation

**← Previous:** [npm error code E401 on Launch: install private packages](https://developers.contentstack.com/guides/fix-failing-launch-builds/private-npm-packages-and-e401)

