refinedev/refine · error · Error

./package.json not found

Error message

./package.json not found

What it means

refine CLI utilities require the command to run inside a Node project: getPackageJson checks for a package.json in the current working directory and throws when absent before reading dependencies or installing packages.

Source

Thrown at packages/cli/src/utils/package/index.ts:12

import spinner from "@utils/spinner";
import execa from "execa";
import { existsSync, pathExists, readFileSync, readJSON } from "fs-extra";
import globby from "globby";
import path from "path";
import preferredPM from "preferred-pm";
import type { PackageJson } from "../../definitions/package";

export const getPackageJson = (): PackageJson => {
  if (!existsSync("package.json")) {
    console.error("❌ `package.json` not found.");
    throw new Error("./package.json not found");
  }

  return JSON.parse(readFileSync("package.json", "utf8"));
};

export const getDependencies = () => {
  const packageJson = getPackageJson();
  return Object.keys(packageJson.dependencies || {});
};

export const getDependenciesWithVersion = () => {
  const packageJson = getPackageJson();
  return packageJson?.dependencies || {};
};

export const getDevDependencies = () => {
  const packageJson = getPackageJson();
  return Object.keys(packageJson.devDependencies || {});

View on GitHub (pinned to 779d52a20e)

Solutions

  1. cd into the project root that contains package.json and re-run the command
  2. If starting fresh, run `npm init -y` (or use a starter/create-refine-app) first
  3. In monorepos, run the command in the package workspace that has its own package.json

Example fix

# before
mkdir my-app && cd my-app && refine add provider supabase
# after
npm init -y && refine add provider supabase
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
if (!fs.existsSync('package.json')) process.exit(1); // or npm init first

Prevention

When it happens

Trigger: Running refine CLI commands that need dependencies (e.g. `refine add ...`) from a directory that is not a Node project root — no ./package.json exists in cwd.

Common situations: Running the CLI in a fresh/empty folder, from a subdirectory of a monorepo without its own package.json, or in a project scaffolded with a different layout.

Related errors


AI-assisted analysis of refinedev/refine@779d52a20e (2026-08-27). Data as JSON: /api/errors/8575f2808ff1fdc4. Report an issue: GitHub.