remix-run/react-router · error · Error
package.json does not exist in
Error message
package.json does not exist in ${ctx.cwd} What it means
After copying the template into the project directory, updatePackageJSON() requires a package.json there because it rewrites react-router dependency versions and the project name. A template without a package.json is not a valid React Router project, so the CLI aborts with the resolved project path in the message.
Solutions
- Point --template at the directory that actually contains package.json
- Add a package.json (with react-router / @react-router/* dependencies) to your template root
- Re-pack the tarball so package.json sits at the archive root's top level
Example fix
# before: repo root has no package.json at that level npx create-react-router my-app --template https://github.com/acme/mono/tree/main/packages # after: point at the actual app package npx create-react-router my-app --template https://github.com/acme/mono/tree/main/packages/app
Defensive patterns
Strategy: validation
Validate before calling
import { existsSync } from "node:fs";
import path from "node:path";
function templateHasPackageJson(templateDir: string): boolean {
return existsSync(path.join(templateDir, "package.json"));
}
if (!templateHasPackageJson(templateDir)) {
throw new Error("Template must be a React Router project containing package.json");
} Try / catch
try {
await createReactRouter(args);
} catch (e) {
const msg = e instanceof Error ? e.message : String(e);
if (/package\.json does not exist in/.test(msg)) {
console.error("Template lacks package.json — point --template at the app package directory.");
process.exit(1);
}
throw e;
} Prevention
- Author custom templates from a working create-react-router project so package.json is guaranteed
- When packing tarballs, keep package.json at the root level (top dir is stripped on extract)
- Verify template structure in CI with a check job before publishing
When it happens
Trigger: --template pointing at a repo subdirectory that is not an app (a docs/ folder, an example with only a README); a custom template directory missing package.json; a tarball whose project files are nested one level below the root that strip-1 extraction removes.
Common situations: Pointing at a monorepo root or wrong folder; hand-built templates without a manifest; tarballs packed with an extra top-level directory.
Related errors
- package.json are invalid
- " " is an invalid template. Run to see supported template…
- The path " " was not found in this
- The provided template is not a valid local directory or…
- There was a problem extracting the file from the provided…
AI-assisted analysis of remix-run/react-router@6beaca3952 (2026-08-18).
Data as JSON: /api/errors/ff07dfaccd7007d0.
Report an issue: GitHub.
Appendix: 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 6beaca3952)