remix-run/react-router · error · Error

package.json does not exist in ${ctx.cwd}

Error message

package.json does not exist in ${ctx.cwd}

What it means

Thrown in updatePackageJSON() when, after copying the template into ctx.cwd, no package.json exists at <cwd>/package.json. The CLI requires every template to be a React Router project, which means it must ship a package.json. Its absence means the template itself is not a valid project, or the copy step was filtered down to nothing.

Source

Thrown at packages/create-react-router/index.ts:666

              ? `${command} exited with signal ${signal}`
              : `${command} exited with code ${code}`,
          ),
        );
      }
    });
  });
}

async function updatePackageJSON(ctx: Context) {
  let packageJSONPath = path.join(ctx.cwd, "package.json");
  if (!existsSync(packageJSONPath)) {
    let relativePath = path.relative(process.cwd(), ctx.cwd);
    error(
      "Oh no!",
      "The provided template must be a React Router project with a `package.json` " +
        `file, but that file does not exist in ${color.bold(relativePath)}.`,
    );
    throw new Error(`package.json does not exist in ${ctx.cwd}`);
  }

  let contents = await readFile(packageJSONPath, "utf-8");
  let packageJSON: any;
  try {
    packageJSON = JSON.parse(contents);
    if (!isValidJsonObject(packageJSON)) {
      throw Error();
    }
  } catch (err) {
    error(
      "Oh no!",
      "The provided template must be a React Router project with a `package.json` " +
        `file, but that file is invalid.`,
    );
    throw err;
  }

View on GitHub (pinned to 1fd704a7da)

Solutions

  1. Open the template source and confirm a package.json exists at its root (or chosen subdirectory).
  2. Switch to the official default template by omitting --template.
  3. If the template lives in a subdirectory, point --template at that exact subdirectory (owner/repo/subdir or /tree/:branch/:dir).
  4. If the template is yours, add a minimal package.json with name/version/scripts before publishing.

Example fix

// before -- subdir has no package.json
create-react-router my-app --template https://github.com/acme/mono/tree/main/docs
// after -- point at the actual project subdir
create-react-router my-app --template https://github.com/acme/mono/tree/main/apps/web
Defensive patterns

Strategy: validation

Validate before calling

import fs from 'node:fs';
import path from 'node:path';
function templateHasPackageJson(templateRoot: string): boolean {
  return fs.existsSync(path.join(templateRoot, 'package.json'));
}
// Before relying on a custom template, assert templateHasPackageJson(dir).

Prevention

When it happens

Trigger: Using --template that points at a docs directory, a single example file, or a non-project folder that has no package.json; the template tarball's top-level was stripped incorrectly (strip:1 removed the only layer that contained package.json); a GitHub subdirectory that is documentation-only.

Common situations: Pointing at a monorepo subpackage that has no package.json (e.g. /docs or /examples with nested projects); a community template that isn't actually a React Router project; copy filter removed everything because the archive layout differed.

Related errors


AI-assisted analysis of remix-run/react-router@1fd704a7da (2026-08-12). Data as JSON: /api/errors/ff07dfaccd7007d0. Report an issue: GitHub.