remix-run/react-router · error · Error
Could not find package.json in ${rootDirectory} or any of it
Error message
Could not find package.json in ${rootDirectory} or any of its parent directories. Please add a package.json, or provide a custom entry.server.tsx/jsx file in your app directory. What it means
Thrown during entry-server resolution when no custom entry.server file exists in the app directory AND findEntry cannot locate a package.json in rootDirectory or any parent (walkParents: true). React Router needs package.json both to choose the default entry.server (node vs web) and to ensure the isbot dependency is present; without it, defaulting cannot proceed safely. The message suggests either adding a package.json or providing a custom app/entry.server.tsx/jsx.
Source
Thrown at packages/react-router-dev/config/config.ts:1047
);
let userEntryClientFile = findEntry(appDirectory, "entry.client");
let userEntryServerFile = findEntry(appDirectory, "entry.server");
let entryServerFile: string;
let entryClientFile = userEntryClientFile || "entry.client.tsx";
if (userEntryServerFile) {
entryServerFile = userEntryServerFile;
} else {
let packageJsonPath = findEntry(rootDirectory, "package", {
extensions: [".json"],
absolute: true,
walkParents: true,
});
if (!packageJsonPath) {
throw new Error(
`Could not find package.json in ${rootDirectory} or any of its parent directories. Please add a package.json, or provide a custom entry.server.tsx/jsx file in your app directory.`,
);
}
let packageJsonDirectory = Path.dirname(packageJsonPath);
let pkgJson = await readPackageJSON(packageJsonDirectory);
let deps = pkgJson.dependencies ?? {};
if (!deps["isbot"]) {
console.log(
"adding `isbot@5` to your package.json, you should commit this change",
);
await updatePackage(packageJsonPath, (pkg) => {
pkg.dependencies ??= {};
pkg.dependencies.isbot = "^5";
sortPackage(pkg);
});View on GitHub (pinned to 1fd704a7da)
Solutions
- Ensure a package.json exists at or above the project root (npm init -y in the project directory).
- Run react-router build from the directory that contains package.json.
- Add a custom app/entry.server.tsx (or .jsx) so the default-resolution path that needs package.json is skipped.
- If in a monorepo, confirm the tool resolves the workspace root that contains package.json; check rootDirectory in react-router.config.ts.
- Reinstall dependencies (npm install) so isbot and other deps are present after adding package.json.
Example fix
// before -- project dir has no package.json and no custom entry server react-router build // after -- add package.json (or add app/entry.server.tsx) npm init -y && npm install && react-router build // alternative: create app/entry.server.tsx to bypass default resolution
Defensive patterns
Strategy: validation
Validate before calling
import fs from 'node:fs';
import path from 'node:path';
function hasPackageJsonUpTree(start: string): boolean {
let dir = start;
while (true) {
if (fs.existsSync(path.join(dir, 'package.json'))) return true;
const parent = path.dirname(dir);
if (parent === dir) return false;
dir = parent;
}
}
// if (!hasPackageJsonUpTree(rootDirectory)) -> create package.json or add app/entry.server.tsx Prevention
- Always scaffold with a package.json at the project root (npm init -y).
- Run react-router build from the directory containing package.json.
- Provide a custom app/entry.server.tsx if you intentionally have no package.json.
- In monorepos, double-check rootDirectory/appDirectory in react-router.config.ts.
When it happens
Trigger: Running react-router build/dev in a directory that has no package.json anywhere up the tree (e.g. scaffolding files by hand, or pointing the tool at a bare subfolder); the project root was misconfigured; package.json was deleted or never created; running inside a sandbox that excludes the parent package.json.
Common situations: Standalone experiment folders without package.json; an incorrectly set rootDirectory/appDirectory; monorepo where the tool was invoked from a directory above the package; filesystem permission issue hiding package.json.
Related errors
- React Router presets must have a `name` property defined.
- Unable to define routes with duplicate route id: "${id}"
- React Router Vite plugin not found in Vite config
- The React Router Vite plugin requires the use of a Vite conf
- ${configResult.error}
AI-assisted analysis of remix-run/react-router@1fd704a7da (2026-08-12).
Data as JSON: /api/errors/43fced40773cdd45.
Report an issue: GitHub.