remix-run/react-router · error · Error
Could not find package.json in
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
When the app has no custom entry.server file, resolveEntryFiles() walks rootDirectory and all parent directories looking for package.json: it reads dependencies to choose between the node and web default entry.server and to auto-install isbot if missing. If no package.json exists anywhere above the root, it throws this error suggesting either a package.json or a custom entry.server.
Solutions
- Add a package.json at the project root (npm init -y, then install react-router dependencies)
- Or provide your own app/entry.server.tsx (or .jsx) so the default resolution and isbot check are skipped
- Verify the rootDirectory passed to the tooling points at your React Router app package
Example fix
# before: bare directory, no manifest react-router dev # -> Could not find package.json ... # after: add a manifest and deps, or add app/entry.server.tsx npm init -y && npm install react-router @react-router/dev @react-router/serve # or: create app/entry.server.tsx to bypass default resolution
Defensive patterns
Strategy: validation
Validate before calling
import { existsSync } from "node:fs";
import path from "node:path";
function hasPackageJsonAtOrAbove(dir: string): boolean {
let cur = path.resolve(dir);
for (;;) {
if (existsSync(path.join(cur, "package.json"))) return true;
const parent = path.dirname(cur);
if (parent === cur) return false;
cur = parent;
}
}
const hasCustomEntryServer = ["entry.server.tsx", "entry.server.jsx"]
.some((f) => existsSync(path.join(appDirectory, f)));
if (!hasPackageJsonAtOrAbove(rootDirectory) && !hasCustomEntryServer) {
throw new Error("Add a package.json above the app root, or provide app/entry.server.tsx");
} Prevention
- Always scaffold React Router apps inside a package with a package.json (create-react-router does this for you)
- Provide a custom app/entry.server.tsx when you cannot guarantee a manifest above the root
- When calling @react-router/dev programmatically, validate rootDirectory points at the app package
When it happens
Trigger: Invoking @react-router/dev build/dev APIs with a rootDirectory that has no package.json above it (bare directory, deleted manifest, wrong root passed by a generator); unusual workspaces where the app root sits outside any package tree.
Common situations: Experimental setups and custom scaffolds calling the dev package programmatically; monorepo tooling misconfiguring the root directory; package.json accidentally removed.
Related errors
- React Router presets must have a `name` property defined.
- Route config file not found at
- Could not find a root route module in the app directory
- Could not find a root route module in the app directory as
- Could not find the routes directory
AI-assisted analysis of remix-run/react-router@6beaca3952 (2026-08-18).
Data as JSON: /api/errors/43fced40773cdd45.
Report an issue: GitHub.
Appendix: 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 6beaca3952)